@font-face {
  font-family: "CNSParts";
  src: url("./cns11643webv5.woff") format("woff");
  font-display: swap;
}

:root {
  --ink: #432214;
  --ink-soft: rgba(67, 34, 20, 0.7);
  --paper: #ead28f;
  --paper-deep: #d9bb71;
  --paper-shadow: rgba(78, 41, 16, 0.18);
  --blue-line: rgba(45, 92, 146, 0.84);
  --blue-fill: rgba(98, 139, 182, 0.12);
  --blue-glow: rgba(52, 121, 197, 0.24);
  --red-line: rgba(162, 36, 31, 0.88);
  --red-fill: rgba(175, 53, 49, 0.08);
  --red-glow: rgba(187, 51, 45, 0.26);
  --success: #856a17;
  --shell-width: 560px;
  --pool-panel-height: clamp(196px, 52vw, 286px);
  --transition: 180ms ease;
  --viewport-height: 100vh;
  --stage-outer-gap: 28px;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 245, 196, 0.28), transparent 22%),
    radial-gradient(circle at 20% 20%, rgba(255, 232, 172, 0.08), transparent 24%),
    radial-gradient(circle at 80% 72%, rgba(134, 76, 28, 0.1), transparent 20%),
    linear-gradient(180deg, #6d481e 0%, #4f3117 38%, #351c0e 100%);
  color: var(--ink);
  font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
}

body {
  display: grid;
  place-items: center;
  min-height: var(--viewport-height);
  min-height: 100dvh;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

button {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
}

.app-shell {
  width: min(var(--shell-width), 100%);
  max-width: 100%;
}

.paper-stage {
  position: relative;
  display: grid;
  gap: 18px;
  min-height: min(calc(var(--viewport-height) - var(--stage-outer-gap)), 860px);
  min-height: min(calc(100dvh - var(--stage-outer-gap)), 860px);
  padding:
    22px
    18px
    max(20px, calc(env(safe-area-inset-bottom) + 10px))
    18px;
  border-radius: 26px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 248, 219, 0.42), rgba(239, 211, 135, 0.24)),
    linear-gradient(180deg, rgba(186, 144, 70, 0.15), rgba(139, 95, 34, 0.1)),
    repeating-linear-gradient(
      0deg,
      rgba(151, 111, 56, 0.045) 0,
      rgba(151, 111, 56, 0.045) 2px,
      transparent 2px,
      transparent 10px
    ),
    linear-gradient(180deg, #f0da9b 0%, #e8cb82 100%);
  box-shadow:
    0 28px 70px rgba(21, 9, 3, 0.35),
    inset 0 0 0 1px rgba(118, 77, 20, 0.2),
    inset 0 10px 30px rgba(255, 247, 214, 0.35);
  touch-action: none;
}

.paper-stage::before,
.paper-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.paper-stage::before {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.38), transparent 28%),
    radial-gradient(circle at 50% 100%, rgba(114, 62, 20, 0.12), transparent 26%);
  mix-blend-mode: screen;
}

.paper-stage::after {
  inset: 10px;
  border: 1px solid rgba(128, 83, 25, 0.22);
  border-radius: 18px;
}

.seal-stamp {
  position: absolute;
  top: 18px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  place-items: center;
  width: 68px;
  aspect-ratio: 1;
  padding: 5px 4px 4px;
  border-radius: 3px;
  box-shadow:
    inset 0 0 0 1px currentColor,
    inset 0 0 0 4px rgba(0, 0, 0, 0.035),
    0 8px 14px rgba(52, 24, 10, 0.12);
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", "PMingLiU", serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.08em;
  line-height: 1;
  cursor: pointer;
  transition: transform var(--transition), opacity var(--transition), box-shadow var(--transition);
}

.seal-stamp span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.seal-stamp:hover,
.seal-stamp:active {
  transform: scale(1.03);
  opacity: 1;
  box-shadow:
    inset 0 0 0 1px currentColor,
    inset 0 0 0 4px rgba(0, 0, 0, 0.05),
    0 10px 18px rgba(52, 24, 10, 0.16);
}

.seal-stamp-achievement {
  left: 18px;
  color: rgba(23, 18, 16, 0.94);
  border: 3px solid rgba(23, 18, 16, 0.94);
  background:
    linear-gradient(180deg, rgba(38, 32, 29, 0.1), rgba(38, 32, 29, 0.03)),
    repeating-linear-gradient(
      90deg,
      rgba(23, 18, 16, 0.055) 0,
      rgba(23, 18, 16, 0.055) 1px,
      transparent 1px,
      transparent 7px
    );
  transform: rotate(-3deg);
}

.seal-stamp-skip {
  right: 18px;
  color: rgba(157, 22, 18, 0.96);
  border: 3px solid rgba(165, 35, 30, 0.9);
  background:
    linear-gradient(180deg, rgba(216, 70, 60, 0.16), rgba(136, 17, 13, 0.07)),
    repeating-linear-gradient(
      90deg,
      rgba(165, 35, 30, 0.055) 0,
      rgba(165, 35, 30, 0.055) 1px,
      transparent 1px,
      transparent 7px
    );
  transform: rotate(2deg);
}

.progress-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px 14px;
  background: rgba(47, 23, 11, 0.34);
  backdrop-filter: blur(3px);
}

.progress-backdrop[hidden] {
  display: none;
}

.progress-popup {
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(100%, 456px);
  max-height: min(86svh, 720px);
  border-radius: 20px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 248, 222, 0.94), rgba(236, 210, 138, 0.96)),
    linear-gradient(180deg, rgba(175, 136, 66, 0.11), rgba(120, 78, 30, 0.08));
  box-shadow:
    0 24px 48px rgba(31, 16, 7, 0.24),
    inset 0 0 0 1px rgba(128, 83, 25, 0.22);
}

.progress-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(128, 83, 25, 0.12);
}

.progress-title {
  margin: 0;
  font-size: 24px;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
  color: #572114;
}

.progress-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: rgba(67, 34, 20, 0.66);
}

.progress-close {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(117, 41, 30, 0.2);
  background: rgba(255, 255, 255, 0.18);
  color: #7b241b;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
  font-size: 18px;
}

.progress-list {
  overflow: auto;
  padding: 8px 12px 14px;
}

.progress-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px dashed rgba(128, 83, 25, 0.12);
}

.progress-index {
  padding-top: 2px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: rgba(67, 34, 20, 0.58);
}

.progress-clue {
  font-size: 15px;
  line-height: 1.45;
  color: #5b1f14;
  text-align: center;
}

.progress-clue.is-locked {
  color: #2f241d;
  letter-spacing: 0.08em;
}

.progress-answer {
  min-width: 62px;
  text-align: right;
  font-size: 18px;
  color: #392118;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
}

.progress-answer[role="button"] {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.progress-meta {
  grid-column: 2 / 4;
  margin-top: 2px;
  font-size: 12px;
  color: rgba(67, 34, 20, 0.46);
}

.progress-answer.is-locked {
  color: #a5261f;
  font-size: 22px;
  letter-spacing: -0.08em;
}

.progress-row.is-solved .progress-answer {
  color: #2e1d15;
}

.progress-row.is-solved .progress-clue {
  color: #4c2417;
}

.riddle-wrap {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  padding: 8px 92px 0;
}

.custom-banner {
  margin: 0;
  min-height: 20px;
  text-align: center;
  color: #b3221f;
  font-size: 12px;
  letter-spacing: 0.12em;
}

.riddle-text {
  margin: 0;
  min-height: 84px;
  padding: 2px 0 6px;
  overflow: hidden;
  text-align: center;
  line-height: 1.48;
  font-size: clamp(22px, 4vw, 32px);
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", "Kaiti SC", serif;
  letter-spacing: 0.08em;
  color: #5b1f14;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status-text {
  margin: 0;
  min-height: 22px;
  text-align: center;
  font-size: 14px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  transition: color var(--transition), opacity var(--transition), transform var(--transition);
}

.level-timer {
  margin: -8px 4px 0;
  min-height: 18px;
  text-align: right;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(83, 45, 21, 0.75);
}

.riddle-text.is-medium {
  font-size: clamp(20px, 3.5vw, 28px);
}

.riddle-text.is-long {
  font-size: clamp(18px, 3vw, 24px);
  letter-spacing: 0.04em;
}

.status-text.is-error {
  color: #9e231f;
}

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

.playfield {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 18px;
  align-content: start;
}

.language-bar {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.language-btn {
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(117, 82, 29, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 253, 237, 0.3), rgba(177, 137, 61, 0.07)),
    rgba(255, 248, 223, 0.32);
  color: rgba(75, 37, 20, 0.9);
  font-size: 13px;
  letter-spacing: 0.06em;
  transition: transform var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.language-btn.is-active {
  background:
    linear-gradient(180deg, rgba(129, 86, 23, 0.24), rgba(129, 86, 23, 0.1)),
    rgba(247, 227, 170, 0.62);
  box-shadow:
    0 8px 16px rgba(62, 35, 11, 0.12),
    inset 0 0 0 1px rgba(117, 82, 29, 0.18);
  color: #4d2413;
}

.language-btn-challenge {
  border-color: rgba(152, 31, 27, 0.24);
  background:
    linear-gradient(180deg, rgba(183, 50, 44, 0.26), rgba(130, 21, 18, 0.08)),
    rgba(255, 236, 225, 0.2);
  color: #7f1c18;
}

.evaluation-backdrop {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(82, 55, 18, 0.22);
  backdrop-filter: blur(2px);
}

.evaluation-backdrop[hidden] {
  display: none;
}

.evaluation-popup {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: min(82vw, 250px);
  padding: 18px 20px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 249, 228, 0.9), rgba(236, 211, 144, 0.92)),
    linear-gradient(180deg, rgba(175, 136, 66, 0.12), rgba(120, 78, 30, 0.08));
  box-shadow:
    0 24px 48px rgba(31, 16, 7, 0.18),
    inset 0 0 0 1px rgba(128, 83, 25, 0.16);
}

.evaluation-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(156, 114, 44, 0.22);
  border-top-color: rgba(131, 77, 23, 0.86);
  animation: evaluation-spin 720ms linear infinite;
}

.evaluation-title {
  margin: 0;
  font-size: 24px;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
  color: #5b1f14;
}

.evaluation-subtitle {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: rgba(67, 34, 20, 0.72);
}

.pool-panel,
.answer-panel {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

.pool-panel {
  display: grid;
  gap: 10px;
  min-height: var(--pool-panel-height);
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, rgba(72, 122, 178, 0.11), rgba(72, 122, 178, 0.03));
}

.pool-panel::before,
.answer-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pool-panel::before {
  background:
    linear-gradient(var(--blue-line), var(--blue-line)) 0 0 / 100% 1px no-repeat,
    linear-gradient(var(--blue-line), var(--blue-line)) 0 100% / 100% 1px no-repeat,
    linear-gradient(90deg, var(--blue-line), var(--blue-line)) 0 0 / 1px 100% no-repeat,
    linear-gradient(90deg, var(--blue-line), var(--blue-line)) 100% 0 / 1px 100% no-repeat;
  opacity: 0.5;
}

.pool-pager {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.pool-pager[hidden] {
  display: none;
}

.pool-page-btn {
  min-width: 44px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(45, 92, 146, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.26), rgba(72, 122, 178, 0.08)),
    rgba(98, 139, 182, 0.12);
  color: #274461;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
  font-size: 18px;
  transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
}

.pool-page-btn:disabled {
  opacity: 0.34;
}

.pool-page-indicator {
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: rgba(39, 68, 97, 0.76);
}

.answer-panel {
  min-height: 330px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, rgba(182, 59, 49, 0.11), rgba(182, 59, 49, 0.03));
}

.answer-panel::before {
  background:
    linear-gradient(var(--red-line), var(--red-line)) 0 0 / 100% 1px no-repeat,
    linear-gradient(var(--red-line), var(--red-line)) 0 100% / 100% 1px no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 0 0 / 1px 100% no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 100% 0 / 1px 100% no-repeat;
  opacity: 0.56;
}

.pool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.submit-ticket {
  display: grid;
  place-items: center;
  min-width: 132px;
  min-height: 78px;
  margin: 0 auto;
  padding: 4px 10px 2px;
  border: 2px solid rgba(27, 50, 118, 0.92);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(40, 71, 154, 0.2), rgba(17, 36, 98, 0.06)),
    repeating-linear-gradient(
      90deg,
      rgba(27, 50, 118, 0.08) 0,
      rgba(27, 50, 118, 0.08) 1px,
      transparent 1px,
      transparent 7px
    ),
    rgba(238, 244, 255, 0.16);
  color: rgba(24, 46, 112, 0.96);
  font-family: "Songti TC", "STSong", "PMingLiU", "MingLiU", "Noto Serif CJK TC", "Noto Serif TC", serif;
  font-size: clamp(28px, 5vw, 36px);
  font-weight: 500;
  font-synthesis: none;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  box-shadow:
    inset 0 0 0 1px currentColor,
    inset 0 0 0 4px rgba(27, 50, 118, 0.04),
    0 10px 18px rgba(23, 34, 83, 0.14);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transform: scale(0.82);
  opacity: 0;
}

.submit-ticket[hidden] {
  display: none;
}

.submit-ticket.is-popping {
  animation: submit-ticket-pop 180ms cubic-bezier(0.18, 0.82, 0.24, 1.16) forwards;
}

.submit-ticket.is-breathing {
  opacity: 1;
  transform: scale(1);
  animation: submit-ticket-breathe 1800ms ease-in-out infinite;
}

.playfield.is-submit-mode .pool-panel {
  min-height: var(--pool-panel-height);
  padding: 14px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.playfield.is-submit-mode .pool-grid,
.playfield.is-submit-mode .pool-pager {
  display: none;
}

.pool-slot {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  background:
    linear-gradient(var(--blue-line), var(--blue-line)) 0 0 / 100% 1px no-repeat,
    linear-gradient(var(--blue-line), var(--blue-line)) 0 100% / 100% 1px no-repeat,
    linear-gradient(90deg, var(--blue-line), var(--blue-line)) 0 0 / 1px 100% no-repeat,
    linear-gradient(90deg, var(--blue-line), var(--blue-line)) 100% 0 / 1px 100% no-repeat,
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(51, 107, 170, 0.04));
  box-shadow: inset 0 0 0 1px rgba(46, 92, 146, 0.06);
}

.answer-panel[data-cells="2"] {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.answer-panel[data-cells="2"] .answer-cell {
  aspect-ratio: 1 / 1;
  min-height: auto;
}

.answer-panel[data-cells="3"] {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.answer-cell {
  position: relative;
  min-height: 302px;
  border-radius: 18px;
  background:
    linear-gradient(var(--red-line), var(--red-line)) 0 0 / 100% 2px no-repeat,
    linear-gradient(var(--red-line), var(--red-line)) 0 100% / 100% 2px no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 0 0 / 2px 100% no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 100% 0 / 2px 100% no-repeat,
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(146, 17, 12, 0.02));
  box-shadow:
    inset 0 0 0 1px rgba(162, 36, 31, 0.06),
    0 10px 18px rgba(93, 35, 21, 0.09);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.solved-circle {
  position: absolute;
  inset: -3% -3%;
  width: 106%;
  height: 106%;
  opacity: 0.9;
  pointer-events: none;
  z-index: 30;
}

.failed-cross {
  position: absolute;
  inset: -3% -3%;
  width: 106%;
  height: 106%;
  opacity: 0.94;
  pointer-events: none;
  z-index: 31;
}

.failed-cross.is-fading {
  opacity: 0;
  transition: opacity 300ms ease;
}

.answer-panel[data-cells="3"] .answer-cell {
  aspect-ratio: 1 / 1;
  min-height: auto;
}

.answer-cell::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(162, 36, 31, 0.16);
  border-radius: 12px;
  pointer-events: none;
}

.answer-cell.is-failed {
  box-shadow:
    inset 0 0 0 2px rgba(174, 36, 31, 0.18),
    0 0 0 4px rgba(174, 36, 31, 0.12),
    0 12px 24px rgba(139, 28, 25, 0.18);
  animation: cell-flash 540ms ease 2;
}

.answer-cell.is-solved {
  box-shadow:
    inset 0 0 0 2px rgba(120, 100, 23, 0.16),
    0 0 0 4px rgba(160, 135, 41, 0.12),
    0 14px 26px rgba(120, 96, 26, 0.16);
}

.part-token {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  cursor: pointer;
  transform-origin: center;
  transform: scale(var(--token-scale, 1));
  transition:
    transform var(--transition),
    box-shadow var(--transition),
    color var(--transition),
    background-color var(--transition),
    opacity var(--transition);
  color: #1f3349;
  font-family: "CNSParts", "Songti TC", serif;
  font-size: clamp(32px, 6vw, 48px);
  line-height: 1;
}

.part-token::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.38), transparent 46%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 58%);
  opacity: 0.72;
  pointer-events: none;
}

.pool-slot > .part-token {
  background-color: var(--blue-fill);
  box-shadow:
    0 12px 18px rgba(29, 74, 123, 0.1),
    inset 0 0 0 1px rgba(50, 110, 178, 0.1);
}

.answer-token {
  position: absolute;
  width: 30%;
  height: 22%;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  transform: translate(-50%, -50%);
  background-color: transparent;
}

.answer-token .part-token {
  background-color: rgba(255, 255, 255, 0.02);
}

.answer-token .part-token::before {
  opacity: 0.46;
}

.part-token.is-selected {
  color: #10253a;
  box-shadow:
    0 0 0 3px var(--blue-glow),
    0 12px 22px rgba(42, 88, 146, 0.15);
}

.answer-token .part-token.is-selected {
  box-shadow:
    0 0 0 3px rgba(182, 46, 41, 0.18),
    0 12px 22px rgba(141, 38, 35, 0.14);
}

.part-token.is-failed {
  color: #a22922;
}

.part-token.is-hidden {
  opacity: 0.14;
}

.drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.drag-ghost {
  position: fixed;
  width: 86px;
  height: 72px;
  transform: translate(-50%, -50%) scale(1.08);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(59, 113, 177, 0.08)),
    rgba(104, 145, 188, 0.16);
  box-shadow:
    0 18px 30px rgba(20, 12, 6, 0.24),
    0 0 0 4px rgba(52, 121, 197, 0.14);
}

.drag-ghost.is-answer {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(187, 66, 46, 0.08)),
    rgba(186, 67, 57, 0.12);
  box-shadow:
    0 18px 30px rgba(20, 12, 6, 0.24),
    0 0 0 4px rgba(187, 66, 46, 0.14);
}

.drag-ghost .part-token {
  font-size: 46px;
}

.toast {
  position: absolute;
  inset: auto 18px 18px;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(82, 51, 14, 0.84);
  color: #fff5d9;
  text-align: center;
  letter-spacing: 0.18em;
  box-shadow: 0 14px 26px rgba(38, 20, 6, 0.28);
  animation: toast-in 260ms ease;
}

.detail-backdrop,
.challenge-backdrop {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(47, 23, 11, 0.34);
  backdrop-filter: blur(2px);
}

.detail-backdrop[hidden],
.challenge-backdrop[hidden] {
  display: none;
}

.detail-popup {
  width: min(100%, 380px);
  padding: 14px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 248, 222, 0.94), rgba(236, 210, 138, 0.96)),
    linear-gradient(180deg, rgba(175, 136, 66, 0.11), rgba(120, 78, 30, 0.08));
  box-shadow:
    0 20px 38px rgba(31, 16, 7, 0.2),
    inset 0 0 0 1px rgba(128, 83, 25, 0.22);
}

.detail-title {
  margin: 0 0 10px;
  text-align: center;
  font-size: 18px;
  color: #612317;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-grid[data-cells="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-grid[data-cells="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background:
    linear-gradient(var(--red-line), var(--red-line)) 0 0 / 100% 2px no-repeat,
    linear-gradient(var(--red-line), var(--red-line)) 0 100% / 100% 2px no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 0 0 / 2px 100% no-repeat,
    linear-gradient(90deg, var(--red-line), var(--red-line)) 100% 0 / 2px 100% no-repeat,
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(146, 17, 12, 0.03));
}

.detail-token {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: 30%;
  height: 22%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  color: #1f3349;
  font-family: "CNSParts", "Songti TC", serif;
  font-size: clamp(22px, 4vw, 30px);
  transform-origin: center;
}

.detail-token > span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transform: scale(var(--token-scale, 1));
}

.challenge-popup {
  width: min(100%, 430px);
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 248, 222, 0.96), rgba(236, 210, 138, 0.98)),
    linear-gradient(180deg, rgba(175, 136, 66, 0.11), rgba(120, 78, 30, 0.08));
  box-shadow:
    0 20px 38px rgba(31, 16, 7, 0.2),
    inset 0 0 0 1px rgba(128, 83, 25, 0.22);
}

.challenge-title {
  margin: 0;
  text-align: center;
  font-size: 22px;
  color: #612317;
  font-family: "BiauKai", "DFKai-SB", "Kaiti TC", serif;
}

.challenge-field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #5a2818;
}

.challenge-field textarea,
.challenge-field input {
  width: 100%;
  border: 1px solid rgba(117, 82, 29, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.48);
  color: #3f2315;
  padding: 10px;
  font: inherit;
  outline: none;
}

.challenge-field textarea {
  resize: none;
  min-height: 90px;
}

.challenge-note {
  margin: 0;
  min-height: 18px;
  text-align: center;
  font-size: 12px;
  color: #7d271f;
  line-height: 1.6;
  word-break: break-all;
}

.challenge-link {
  color: #8a1f1a;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.challenge-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.challenge-btn {
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(117, 82, 29, 0.2);
  background: rgba(255, 255, 255, 0.25);
  color: #4a2314;
  font-size: 14px;
}

.challenge-btn-confirm {
  border-color: rgba(152, 31, 27, 0.26);
  background:
    linear-gradient(180deg, rgba(183, 50, 44, 0.22), rgba(130, 21, 18, 0.08)),
    rgba(255, 236, 225, 0.18);
  color: #7f1c18;
}

.fireworks-layer {
  position: absolute;
  inset: 0;
  z-index: 17;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.fireworks-layer.is-active {
  opacity: 1;
}

@keyframes cell-flash {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }

  50% {
    filter: brightness(1.08);
    transform: scale(1.01);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes submit-ticket-pop {
  from {
    opacity: 0;
    transform: scale(0.66);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes submit-ticket-breathe {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.035);
  }
}

@keyframes evaluation-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 520px) {
  :root {
    --stage-outer-gap: 20px;
  }

  .paper-stage {
    min-height: min(calc(var(--viewport-height) - var(--stage-outer-gap)), 820px);
    min-height: min(calc(100dvh - var(--stage-outer-gap)), 820px);
    padding:
      18px
      14px
      max(24px, calc(env(safe-area-inset-bottom) + 12px))
      14px;
    gap: 16px;
  }

  .seal-stamp {
    top: 14px;
    width: 58px;
    padding: 4px 3px 3px;
    font-size: 19px;
  }

  .seal-stamp-achievement {
    left: 14px;
  }

  .seal-stamp-skip {
    right: 14px;
  }

  .riddle-text {
    min-height: 74px;
    padding-bottom: 5px;
    font-size: clamp(20px, 5.2vw, 28px);
  }

  .riddle-wrap {
    padding: 0 74px;
  }

  .pool-grid {
    gap: 8px;
  }

  .language-bar {
    gap: 6px;
  }

  .language-btn {
    min-height: 34px;
    font-size: 12px;
    letter-spacing: 0.04em;
  }

  .pool-pager {
    grid-template-columns: 40px 1fr 40px;
    gap: 8px;
  }

  .submit-ticket {
    min-width: 118px;
    min-height: 70px;
    font-size: clamp(24px, 7vw, 32px);
  }

  .pool-page-btn {
    min-width: 40px;
    min-height: 34px;
    font-size: 16px;
  }

  .answer-panel {
    min-height: 300px;
    padding: 10px;
  }

  .answer-cell {
    min-height: 278px;
  }

  .answer-panel[data-cells="3"] .answer-cell {
    aspect-ratio: 1 / 1;
    min-height: auto;
  }

  .answer-token {
    width: 34%;
    height: 20%;
  }

  .part-token {
    font-size: clamp(28px, 7vw, 44px);
  }

  .progress-popup {
    max-height: min(88svh, 680px);
  }

  .level-timer {
    font-size: 11px;
  }

  .challenge-popup {
    padding: 14px;
  }

  .detail-popup {
    width: min(100%, 340px);
  }

  .progress-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .progress-answer {
    min-width: 50px;
    font-size: 17px;
  }

  .progress-answer.is-locked {
    font-size: 20px;
  }
}

@media (max-width: 520px) and (max-height: 900px) {
  :root {
    --pool-panel-height: clamp(164px, 27vh, 214px);
    --stage-outer-gap: 16px;
  }

  body {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .paper-stage {
    gap: 12px;
    padding:
      14px
      12px
      max(18px, calc(env(safe-area-inset-bottom) + 8px))
      12px;
  }

  .seal-stamp {
    top: 10px;
    width: 52px;
    font-size: 17px;
  }

  .seal-stamp-achievement {
    left: 10px;
  }

  .seal-stamp-skip {
    right: 10px;
  }

  .riddle-wrap {
    gap: 4px;
    padding: 0 64px;
  }

  .riddle-text {
    min-height: 62px;
    padding-bottom: 4px;
    font-size: clamp(18px, 4.5vw, 24px);
    line-height: 1.38;
  }

  .status-text {
    min-height: 18px;
    font-size: 12px;
  }

  .playfield {
    gap: 12px;
  }

  .pool-panel {
    padding: 10px;
  }

  .pool-grid {
    gap: 6px;
  }

  .pool-pager {
    gap: 6px;
  }

  .pool-page-btn {
    min-height: 30px;
    font-size: 15px;
  }

  .submit-ticket {
    min-width: 108px;
    min-height: 58px;
    font-size: clamp(22px, 6.4vw, 28px);
  }

  .answer-panel {
    min-height: min(34vh, 248px);
    padding: 8px;
  }

  .answer-panel[data-cells="2"],
  .answer-panel[data-cells="3"] {
    gap: 10px;
  }

  .answer-token {
    width: 28%;
    height: 19%;
  }

  .part-token {
    font-size: clamp(24px, 6.4vw, 38px);
  }

  .level-timer {
    margin-top: -4px;
    font-size: 10px;
  }

  .language-bar {
    gap: 5px;
  }

  .language-btn {
    min-height: 30px;
    font-size: 11px;
  }
}

@media (max-width: 520px) and (max-height: 820px) {
  :root {
    --pool-panel-height: clamp(150px, 24vh, 188px);
  }

  .riddle-wrap {
    padding: 0 58px;
  }

  .riddle-text {
    min-height: 52px;
    font-size: clamp(17px, 4.2vw, 22px);
  }

  .answer-panel {
    min-height: min(31vh, 214px);
  }
}
