
:root {
  --ink: #1c2b33;
  --muted: #4d6470;
  --paper: #fffaf2;
  --paper-2: #f3f8f4;
  --sea: #1f8a70;
  --sea-deep: #146853;
  --sun: #f0a202;
  --coral: #e4572e;
  --line: rgba(28, 43, 51, 0.12);
  --shadow: 0 14px 30px rgba(20, 60, 50, 0.12);
  --radius: 22px;
  --tile: #ffffff;
  --tile-active: #dff7ee;
  --ok: #1f8a70;
  --bad: #c23b22;
  --font-display: "Noto Serif TC", "Songti TC", "PingFang HK", "Hiragino Sans CNS",
    "Source Han Serif TC", serif;
  --font-body: "Noto Sans TC", "PingFang HK", "Hiragino Sans CNS", "Heiti TC",
    "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #d9efe7;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 18%, rgba(240, 162, 2, 0.28), transparent 34%),
    radial-gradient(circle at 88% 10%, rgba(31, 138, 112, 0.22), transparent 32%),
    linear-gradient(165deg, #e8f7f1 0%, #d7ebe4 42%, #f7f1e4 100%);
}

.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Ccircle cx='8' cy='10' r='1.4' fill='%231f8a70' opacity='0.25'/%3E%3Ccircle cx='70' cy='40' r='1' fill='%23f0a202' opacity='0.28'/%3E%3Ccircle cx='100' cy='90' r='1.2' fill='%231c2b33' opacity='0.12'/%3E%3C/svg%3E");
}

.app {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px
    max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.brand-wrap {
  text-align: center;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4.8vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: var(--sea-deep);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-spacer {
  width: 72px;
  height: 1px;
}

.ghost-btn,
.text-btn,
.primary-btn,
.secondary-btn,
.level-card {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.ghost-btn {
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--sea-deep);
  font-weight: 600;
}

.lead {
  margin: 0 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.level-grid {
  display: grid;
  gap: 14px;
}

@media (min-width: 720px) {
  .level-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.level-card {
  display: grid;
  gap: 8px;
  justify-items: start;
  min-height: 150px;
  padding: 22px 22px 20px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--paper), #fff);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.level-card:active {
  transform: scale(0.985);
}

.level-card-advanced {
  background: linear-gradient(160deg, #fff8e8, #fff);
}

.level-name {
  font-family: var(--font-display);
  font-size: 1.85rem;
  color: var(--sea-deep);
}

.level-card-advanced .level-name {
  color: #9a5b00;
}

.level-desc {
  color: var(--muted);
}

.level-progress {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(31, 138, 112, 0.12);
  color: var(--sea-deep);
  font-weight: 700;
}

.level-card-advanced .level-progress {
  background: rgba(240, 162, 2, 0.18);
  color: #8a5200;
}

.text-btn {
  display: block;
  margin: 22px auto 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
}

.play-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  align-items: baseline;
  margin-bottom: 14px;
}

.play-level {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: var(--sea-deep);
}

.play-counter {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.board {
  display: grid;
  gap: 14px;
}

.slot-panel,
.bank-panel {
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(255, 250, 242, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel-label {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 64px;
  align-content: flex-start;
}

.answer-row {
  min-height: 88px;
  padding: 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(31, 138, 112, 0.06), rgba(31, 138, 112, 0.02));
  border: 2px dashed rgba(31, 138, 112, 0.28);
}

.answer-row.drag-over {
  border-color: var(--sea);
  background: rgba(31, 138, 112, 0.12);
}

.tile {
  appearance: none;
  border: 2px solid rgba(28, 43, 51, 0.1);
  border-radius: 16px;
  min-height: 52px;
  min-width: 52px;
  padding: 10px 14px;
  background: var(--tile);
  color: var(--ink);
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.2;
  box-shadow: 0 6px 14px rgba(28, 43, 51, 0.08);
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.tile:active {
  cursor: grabbing;
  transform: scale(1.04);
}

.tile.is-selected {
  background: var(--tile-active);
  border-color: var(--sea);
  box-shadow: 0 0 0 3px rgba(31, 138, 112, 0.18);
}

.tile.is-punct {
  min-width: 44px;
  color: var(--coral);
}

.tile.dragging {
  opacity: 0.45;
}

.feedback {
  min-height: 1.6em;
  margin: 14px 0 0;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}

.feedback.ok {
  color: var(--ok);
}

.feedback.bad {
  color: #c23b22;
}

.feedback.reveal {
  color: #8a5200;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}

.primary-btn,
.secondary-btn {
  min-height: 56px;
  min-width: 140px;
  padding: 0 22px;
  border-radius: 999px;
  border: 0;
  font-size: 1.12rem;
  font-weight: 800;
}

.primary-btn {
  background: linear-gradient(180deg, #2aa987, var(--sea));
  color: #fff;
  box-shadow: 0 10px 20px rgba(31, 138, 112, 0.28);
}

.primary-btn:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.secondary-btn {
  background: #fff;
  color: var(--sea-deep);
  border: 2px solid rgba(31, 138, 112, 0.25);
}

.done-title {
  margin: 40px 0 10px;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  color: var(--sea-deep);
}

.done-message {
  margin: 0 0 24px;
  text-align: center;
  color: var(--muted);
  font-size: 1.1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

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

.view:not([hidden]) {
  animation: pop-in 280ms ease;
}

.level-card:focus-visible,
.tile:focus-visible,
.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.ghost-btn:focus-visible,
.text-btn:focus-visible {
  outline: 3px solid rgba(240, 162, 2, 0.75);
  outline-offset: 3px;
}

.feedback.ok {
  animation: confetti-pulse 420ms ease;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}