:root {
  --ink: #1c1730;
  --muted: #5c5478;
  --line: rgba(28, 23, 48, 0.14);
  --panel: rgba(255, 252, 247, 0.9);
  --accent: #6d28d9;
  --accent-deep: #4c1d95;
  --stamp: #c2410c;
  --danger: #b42318;
  --ok: #0f766e;
  --font-display: "Fraunces", "Songti TC", serif;
  --font-body: "Sora", "PingFang TC", sans-serif;
  --radius: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #f6f1ea;
  line-height: 1.5;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 480px at 8% -12%, #ddd6fe 0%, transparent 55%),
    radial-gradient(700px 420px at 100% 0%, #fed7aa 0%, transparent 50%),
    linear-gradient(165deg, #fffaf4 0%, #f3ece3 100%);
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  width: min(640px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 4rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.tagline {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.nav {
  display: flex;
  gap: 0.35rem;
}

.nav-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn[aria-current="page"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.view[hidden] {
  display: none !important;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.view-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

h1 {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
}

h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.hint {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.hint a,
.ed-id-hint {
  color: var(--accent-deep);
}

.ed-id-hint {
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
}

.quest-list,
.ed-stack {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.7rem;
}

.quest-list li,
.ed-card {
  padding: 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.quest-list .name {
  font-weight: 700;
  font-size: 1.05rem;
}

.quest-list .meta {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.quest-list .actions,
.row-actions,
.play-actions,
.play-voice,
.ed-mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.text-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 12px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.text-btn,
.play-reset,
.scanner-close,
.play-hints-list button,
.play-track button,
.scan-btn {
  touch-action: manipulation;
}

.primary-btn:disabled,
.ghost-btn:disabled,
.danger-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.primary-btn {
  border: none;
  background: var(--accent);
  color: #fff;
}

.primary-btn:hover {
  background: var(--accent-deep);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
}

.danger-btn {
  border: 1px solid rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.25rem 0;
  margin-bottom: 0.75rem;
}

.scan-btn {
  font-size: 1.05rem;
  padding: 0.85rem 1.2rem;
  width: 100%;
  min-height: 3.1rem;
}

.play-cleared-actions {
  margin: 0.85rem 0 0.25rem;
}

.play-cleared-actions[hidden] {
  display: none !important;
}

.play-voice[hidden] {
  display: none !important;
}

.play-advanced {
  margin-top: 1.5rem;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}

.play-advanced summary {
  cursor: pointer;
  font-weight: 500;
  width: fit-content;
}

.play-reset {
  display: inline-block;
  width: max-content;
  max-width: 100%;
  margin: 0.55rem 0 0;
  padding: 0.15rem 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

.play-reset.is-prominent {
  display: block;
  flex: 1 0 100%;
  width: 100%;
  margin: 0;
  min-height: 3.1rem;
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  border: 1px solid rgba(180, 35, 24, 0.4);
  background: rgba(180, 35, 24, 0.14);
  color: var(--danger);
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  font: inherit;
  font-weight: 400;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  width: 100%;
}

.field textarea {
  min-height: 4.5rem;
  resize: vertical;
}

.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-name {
  color: var(--muted);
  font-size: 0.88rem;
}

.import-panel {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.import-step {
  margin: 0 0 0.75rem;
  font-weight: 700;
  font-family: var(--font-display);
}

.import-file-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.import-mode-grid {
  display: grid;
  gap: 0.55rem;
}

.import-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  text-align: left;
  padding: 0.85rem 1rem;
  width: 100%;
}

.mode-desc {
  font-weight: 400;
  font-size: 0.82rem;
  opacity: 0.85;
}

.import-advanced {
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.import-advanced summary {
  cursor: pointer;
  font-weight: 600;
}

.status {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--ok);
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: rgba(15, 118, 110, 0.1);
}

.status:empty,
.status[hidden] {
  display: none !important;
}

.status.is-error {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.08);
}

.status.is-ok {
  color: var(--ok);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.play-progress {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

.play-card {
  margin: 0.5rem 0 1rem;
  padding: 1.1rem 1.15rem 1.2rem;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(76, 29, 149, 0.08);
}

.play-stamp {
  margin: 0 0 0.35rem;
  color: var(--stamp);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.play-body {
  margin: 0.55rem 0 0;
  white-space: pre-wrap;
}

.play-reward {
  margin-top: 0.9rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: rgba(194, 65, 12, 0.1);
  border: 1px dashed rgba(194, 65, 12, 0.4);
}

.play-reward[hidden] {
  display: none !important;
}

.play-reward-label {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--stamp);
}

.play-reward p:last-child {
  margin: 0;
  white-space: pre-wrap;
  font-weight: 600;
}

.play-hints {
  margin: 1rem 0 0;
}

.play-hints[hidden] {
  display: none !important;
}

.play-hints-heading {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.play-hints-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.play-hints-list button {
  width: 100%;
  min-height: 2.85rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
  border: 1px solid rgba(109, 40, 217, 0.28);
  background: rgba(255, 255, 255, 0.72);
  color: inherit;
  padding: 0.7rem 0.85rem;
}

.play-hints-list .hint-title {
  font-weight: 700;
}

.play-hints-list .hint-where {
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
}

.play-track {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.play-track li {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.6rem;
  align-items: stretch;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.92rem;
  overflow: hidden;
}

.play-track li.is-done {
  grid-template-columns: 1fr;
}

.play-track button {
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  min-height: 2.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  box-sizing: border-box;
}

.play-track .track-info {
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.12rem;
}

.play-track li.is-done .track-info {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.play-track .track-title {
  font-weight: 700;
}

.play-track .track-where {
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
}

.play-track .mark {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ok);
  flex-shrink: 0;
}

.play-track .track-check-wrap {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  min-height: 100%;
}

.play-track .track-check {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  isolation: isolate;
  flex: 1 1 auto;
  align-self: stretch;
  width: 100%;
  height: 100%;
  min-height: 3.1rem;
  min-width: 0;
  margin: 0;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
  background: rgba(109, 40, 217, 0.12);
  border-left: 1px solid rgba(109, 40, 217, 0.18);
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.play-track .track-check::before {
  content: "";
  position: absolute;
  inset: 0;
}

.play-track .track-check > * {
  position: relative;
  pointer-events: none;
}

.play-track li.is-locked .track-check {
  color: var(--muted);
  background: transparent;
  border-left-color: var(--line);
}

.play-track li.is-done {
  border-color: rgba(15, 118, 110, 0.35);
}

.play-track li.is-done .mark {
  color: var(--ok);
}

.play-track li.is-open {
  border-color: rgba(109, 40, 217, 0.32);
}

.play-track li.is-locked {
  opacity: 0.55;
}

.play-track li.is-current {
  border-color: rgba(109, 40, 217, 0.45);
  box-shadow: 0 0 0 2px rgba(109, 40, 217, 0.12);
}

.ed-card .ed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.ed-card .ed-num {
  font-family: var(--font-display);
  font-weight: 700;
}

.ed-qr {
  margin-top: 0.65rem;
  width: 108px;
  height: 108px;
  image-rendering: pixelated;
  background: #fff;
  border-radius: 8px;
}

.scanner {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #12081c;
  display: flex;
  flex-direction: column;
}

.scanner[hidden] {
  display: none !important;
}

.scanner video {
  flex: 1;
  width: 100%;
  object-fit: cover;
  background: #000;
}

.scanner-freeze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scanner-freeze[hidden] {
  display: none !important;
}

.scanner.is-hit .scanner-frame {
  display: none;
}

.scanner.is-hit .scanner-msg {
  color: #fde68a;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
}

.scanner-frame {
  position: absolute;
  inset: 22% 12%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(8, 4, 16, 0.35);
  pointer-events: none;
}

.scanner-msg {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5.5rem;
  margin: 0;
  text-align: center;
  color: #fff;
  font-weight: 600;
}

.scanner-close {
  position: absolute;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  font: inherit;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.print-sheets {
  display: grid;
  gap: 1rem;
  margin-top: 1.1rem;
}

.print-card {
  padding: 1.1rem;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: center;
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-card img {
  width: min(240px, 70vw);
  height: auto;
  background: #fff;
}

.print-card .print-num {
  margin: 0;
  color: var(--stamp);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
}

.print-card .print-title {
  margin: 0.25rem 0 0.7rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.print-card .print-id {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
}

@media print {
  .atmosphere,
  .no-print,
  .top,
  .scanner {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .print-sheets {
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
  }

  .print-card {
    border-color: #ccc;
  }
}

@media (max-width: 480px) {
  .view-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
