:root {
  color-scheme: light;
  --theme: #ee4d6a;
  --ink: #2b2d38;
  --sub: #8a8c98;
  --line: #dedee4;
  --bg: #f3f3f3;
  --navy: #363848;
  --soft: color-mix(in srgb, var(--theme) 22%, #fff);
  --danger: #c62f3f;
  --frame: 520px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --edge: max(0px, calc(50vw - var(--frame) / 2));
}

* {
  box-sizing: border-box;
}

html {
  background: #e6e6ea;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic",
    system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid #1d6fd8;
  outline-offset: 2px;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: #1f2230;
  -webkit-box-shadow: 0 0 0 1000px #fff inset;
}

#app {
  max-width: var(--frame);
  margin: 0 auto;
  background: var(--bg);
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- ヘッダー ---- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(42px, auto) 1fr minmax(42px, auto);
  gap: 8px;
  align-items: center;
  height: calc(60px + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  background: var(--theme);
  color: #fff;
}

.bar.dark {
  background: var(--navy);
}

.bar > :first-child {
  justify-self: start;
}

.bar h1 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.bar-btn,
.bar-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: #fff;
}

.bar-text {
  font-size: 16px;
  font-weight: 700;
}

.glass,
.pill,
.caps {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: 42px;
  border: 0;
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.glass {
  width: 42px;
  padding: 0;
}

.pill {
  gap: 6px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

.caps button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 21px;
  background: none;
  color: #fff;
}

/* ---- 入力まわり ---- */
.field {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #1f2230;
  font-size: 16px;
}

.field::placeholder {
  color: #a6a8b3;
}

.field.area {
  padding: 12px 14px;
  line-height: 1.6;
  resize: vertical;
}

.field.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.field.row svg {
  flex: none;
  color: #a6a8b3;
}

.field.center {
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.btn.solid {
  background: var(--navy);
  color: #fff;
}

.btn.plainbtn {
  border-color: #cfd0d8;
  background: #fff;
  color: var(--ink);
}

.btn.danger {
  border-color: #efc3c8;
  background: #fff;
  color: var(--danger);
}

.btn.ghost {
  border: 1px dashed #b9bac2;
  background: none;
  color: #555866;
}

.btn.wide {
  width: 100%;
  margin-top: 28px;
}

.icon-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: #6c6e7a;
}

.hint {
  margin: 4px 2px 0;
  color: var(--sub);
  font-size: 13px;
}

.empty {
  margin: 56px 24px;
  color: var(--sub);
  text-align: center;
}

.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: #cfd0d6;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
}

.switch.on {
  background: #42984e;
}

.switch.on::after {
  left: 21px;
}

.segment {
  display: inline-flex;
  padding: 3px;
  border-radius: 9px;
  background: #e2e2e8;
}

.segment button {
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: #5d5f6b;
  font-size: 13px;
}

.segment button.on {
  background: #fff;
  color: #1f2230;
  font-weight: 700;
}

.segment.full {
  display: flex;
}

.segment.full button {
  flex: 1 1 auto;
  padding: 0 4px;
  white-space: nowrap;
}

/* ---- 一覧 ---- */
.chips {
  display: flex;
  gap: 8px;
  padding: 12px 14px 0;
  overflow-x: auto;
}

.chip {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #d6d6dc;
  border-radius: 8px;
  background: #fff;
  color: #4a4c58;
  font-size: 14px;
}

.chip.on {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
  font-weight: 700;
}

.cards {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 120px;
}

.cards .empty {
  margin: auto;
  color: var(--theme);
  font-size: 17px;
  font-weight: 800;
}

.card.ordering {
  flex-direction: row;
  align-items: center;
}

.card-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.order {
  display: flex;
  flex: none;
  gap: 6px;
}

.order-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #d6d6dc;
  border-radius: 10px;
  background: #fff;
  color: #4a4c58;
}

.order-btn.up svg {
  transform: rotate(-90deg);
}

.order-btn.down svg {
  transform: rotate(90deg);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 14px 16px 16px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  text-align: left;
}

.card.selected {
  outline: 2px solid var(--theme);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--theme);
  font-size: 13px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--theme);
  color: #fff;
}

.card-progress {
  color: #9a9ca6;
  font-size: 13px;
  white-space: nowrap;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.pick {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 2px solid #c5c6ce;
  border-radius: 50%;
  color: #fff;
}

.pick.on {
  border-color: var(--theme);
  background: var(--theme);
}

.fab {
  position: fixed;
  right: calc(var(--edge) + 20px);
  bottom: calc(24px + var(--safe-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--theme);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
  color: #fff;
}

.selectbar {
  position: fixed;
  right: var(--edge);
  bottom: 0;
  left: var(--edge);
  z-index: 5;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
}

.select {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  border: 1px solid #cfd0d8;
  border-radius: 10px;
  background: #fff;
  color: #1f2230;
}

/* ---- 重ねて出すもの（カテゴリー選択・ポップオーバー・メニュー） ---- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 22, 30, 0.45);
}

.scrim.dark {
  background: rgba(0, 0, 0, 0.58);
}

.scrim.pale {
  background: rgba(20, 22, 30, 0.16);
}

.scrim.clear {
  background: transparent;
}

.cat {
  position: fixed;
  top: 50%;
  right: calc(var(--edge) + 22px);
  left: calc(var(--edge) + 22px);
  z-index: 21;
  transform: translateY(-50%);
}

.cat h2 {
  margin: 0 0 16px;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
}

.cat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 70vh;
  padding: 16px;
  overflow-y: auto;
  border-radius: 24px;
  background: #fff;
}

.cat-btn {
  flex: none;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 0;
  border-radius: 16px;
  background: var(--soft);
  color: var(--theme);
  font-size: 16px;
  font-weight: 800;
}

.pop {
  position: fixed;
  top: calc(var(--safe-top) + 62px);
  right: calc(var(--edge) + 14px);
  z-index: 21;
  min-width: 256px;
  padding: 8px;
  border-radius: 24px;
  background: #eeeef0;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.2);
}

.pop-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 0;
  border-radius: 16px;
  background: none;
  color: #1f2230;
  font-size: 17px;
  text-align: left;
}

.pop-row svg {
  flex: none;
}

.pop-row .tick {
  margin-left: auto;
  color: var(--theme);
}

aside.side {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  left: calc(var(--edge) + 10px);
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: clamp(212px, 47vw, 250px);
  padding: 28px 14px 16px;
  overflow-y: auto;
  border-radius: 28px;
  background: var(--theme);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
  color: #fff;
}

.side-art {
  display: flex;
  justify-content: center;
}

.side hr {
  flex: none;
  width: 100%;
  height: 2px;
  margin: 20px 0 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.8);
}

.side-item {
  display: block;
  flex: none;
  width: 100%;
  padding: 13px 2px;
  border: 0;
  background: none;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.side-foot {
  margin-top: auto;
  padding: 20px 4px 0;
  font-size: 14px;
}

.side-foot p {
  margin: 0 0 4px;
}

.side-foot small {
  display: block;
  font-size: 11px;
  line-height: 1.5;
}

.folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8a8c98;
}

.folder-row .field {
  flex: 1;
  min-width: 0;
  min-height: 44px;
}

/* ---- 抽選画面 ---- */
.screen.draw {
  background: var(--theme);
}

.board {
  flex: 1;
  padding: 16px 14px 200px;
  border-radius: 26px 26px 0 0;
  background: #fff;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tiles.text {
  grid-template-columns: repeat(2, 1fr);
}

.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 74px;
  padding: 20px 6px 12px;
  border-radius: 12px;
  background: #f3f3f3;
}

.tile.hit {
  background: var(--soft);
}

.tile-no {
  position: absolute;
  top: 6px;
  left: 9px;
  color: #8f919c;
  font-size: 11px;
}

.tile-val {
  color: #15161c;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.tile.blank .tile-val {
  color: #9a9ca6;
}

.tiles.text .tile-val {
  font-size: 16px;
}

.prize h2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 18px 2px 8px;
  color: var(--theme);
  font-size: 16px;
}

.prize h2 small {
  color: #9a9ca6;
  font-size: 13px;
  font-weight: 400;
}

.more {
  margin: 14px 0 0;
  color: var(--sub);
  font-size: 13px;
  text-align: center;
}

.actions {
  position: fixed;
  right: var(--edge);
  bottom: 0;
  left: var(--edge);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 26px 0 calc(22px + var(--safe-bottom));
  background: linear-gradient(rgba(255, 255, 255, 0), #fff 38%);
  pointer-events: none;
}

.round {
  flex: none;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  pointer-events: auto;
}

.round.main {
  width: 104px;
  height: 104px;
  background: var(--theme);
  font-size: 24px;
}

.round.side {
  width: 76px;
  height: 76px;
  font-size: 14px;
}

.round.tint {
  background: var(--soft);
  color: var(--theme);
}

.round.plain {
  background: #eeeef0;
  color: #1f2230;
}

.round:active {
  filter: brightness(0.92);
}

/* ---- 設定 ---- */
.screen.settings {
  background: var(--navy);
}

.form {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 16px 20px 70px;
  border-radius: 26px 26px 0 0;
  background: var(--bg);
}

.settings .field {
  min-height: 52px;
  border-color: transparent;
  border-radius: 14px;
  font-weight: 700;
}

.label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  color: var(--sub);
  font-size: 14px;
}

.label.center {
  justify-content: center;
}

.q {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  background: none;
  color: #9a9ca6;
}

.range {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--sub);
}

.narrow {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 50%;
  min-width: 190px;
  margin: 0 auto;
}

.narrow .swatch {
  flex: 1;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.prize-row {
  display: grid;
  grid-template-columns: 1fr 76px auto 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.prize-row .count {
  padding: 0 8px;
  text-align: center;
}

.unit {
  color: var(--sub);
  font-size: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow-wrap: anywhere;
}

.check-row input {
  flex: none;
  width: 22px;
  height: 22px;
  accent-color: var(--navy);
}

/* ---- テーマ ---- */
.theme-body {
  padding: 28px 22px 60px;
  text-align: center;
}

.preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius: 30px;
  background: var(--theme);
}

.theme-lead {
  margin: 26px 0;
  color: var(--sub);
  font-size: 14px;
}

.dots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 0;
  justify-items: center;
  max-width: 360px;
  margin: 0 auto;
}

.dot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  color: #fff;
}

.dot.custom {
  border: 2px dashed #b4b6c0;
  background: #fff;
  color: #8a8c98;
  cursor: pointer;
}

.dot.custom.on {
  border: 3px solid var(--ink);
  background: var(--theme);
  color: #fff;
}

.dot.custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ---- 抽選の演出 ---- */
.stage {
  --box: min(100vw - 48px, 420px);
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.stage-box,
.result-card {
  position: relative;
  width: var(--box);
  height: var(--box);
  border-radius: 46px;
}

.stage-box {
  overflow: hidden;
}

.stage-box::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--theme);
  filter: saturate(1.7) brightness(1.04);
}

.stage-box canvas {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.result-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #fff;
  text-align: center;
}

/* 結果のカードは中央から開く */
.result-card.open {
  animation: card-open 0.42s cubic-bezier(0.2, 1.25, 0.4, 1) both;
}

@keyframes card-open {
  from {
    transform: scale(0.05);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.result-cap {
  margin: 0 0 6px;
  color: var(--sub);
  font-size: 17px;
  font-weight: 700;
}

.result-val {
  max-width: 100%;
  margin: 0;
  color: var(--theme);
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

/* 見た目からは外すが、キーボードと読み上げのために残す */
.stage-close {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip-path: inset(50%);
}

/* 数字の書体（メニューで切り替え） */
body[data-font="round"] :is(.tile-val, .result-val) {
  font-family:
    "Hiragino Maru Gothic ProN", "Arial Rounded MT Bold", "Varela Round",
    "Hiragino Sans", sans-serif;
}

body[data-font="serif"] :is(.tile-val, .result-val) {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}

body[data-font="mono"] :is(.tile-val, .result-val) {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- お知らせと確認 ---- */
.toast {
  position: fixed;
  bottom: calc(160px + var(--safe-bottom));
  left: 50%;
  z-index: 60;
  max-width: min(86vw, 440px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #2b2d38;
  color: #fff;
  font-size: 14px;
  transform: translateX(-50%);
}

.dialog-wrap {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 30, 0.5);
}

.dialog {
  width: min(86vw, 340px);
  padding: 22px 20px 16px;
  border-radius: 16px;
  background: #fff;
}

.dialog p {
  margin: 0 0 18px;
}

.dialog-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---- 印刷（PDF 出力） ---- */
#print-area {
  display: none;
}

@media print {
  html,
  body {
    background: #fff;
  }

  #app,
  .stage,
  .toast,
  .dialog-wrap {
    display: none !important;
  }

  #print-area {
    display: block;
    padding: 0 4mm;
    color: #000;
  }

  #print-area h1 {
    margin: 0 0 4px;
    font-size: 20pt;
  }

  #print-area p {
    margin: 0 0 12px;
    font-size: 10pt;
  }

  #print-area table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11pt;
  }

  #print-area th,
  #print-area td {
    padding: 5px 8px;
    border: 1px solid #999;
    text-align: left;
  }

  #print-area .n {
    width: 14mm;
    text-align: right;
  }

  #print-area .v {
    font-weight: 700;
  }

  #print-area .t {
    width: 42mm;
  }
}
