:root {
  --bg: #f3ead9;
  --panel: rgba(255, 249, 240, 0.88);
  --ink: #2f241a;
  --muted: #7a6552;
  --accent: #d95c2b;
  --accent-2: #1f8a70;
  --accent-3: #405cf5;
  --board: #cbb395;
  --cell: rgba(255, 247, 232, 0.35);
  --shadow: 0 16px 32px rgba(92, 52, 20, 0.16);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --tile-gap: 10px;
  --board-size: min(calc(100vw - 26px), calc(100dvh - 368px), 348px);
  --topbar-height: 60px;
  --tabs-height: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background:
    radial-gradient(circle at top, rgba(255, 206, 126, 0.45), transparent 28%),
    linear-gradient(180deg, #f8f2e7 0%, #e8d7bb 100%);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}
button, input { font: inherit; }

.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  gap: 6px;
}

.topbar, .panel-card, .modal-card, .daily-card {
  backdrop-filter: blur(12px);
}

.topbar {
  min-height: var(--topbar-height);
  background: linear-gradient(135deg, rgba(255, 247, 231, 0.96), rgba(247, 227, 198, 0.92));
  border: 1px solid rgba(151, 104, 52, 0.16);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1, h2, h3, .tile {
  font-family: Georgia, "Times New Roman", serif;
}
h1 { margin: 0; font-size: 15px; line-height: 1.05; }
h2 { margin: 0; font-size: 24px; }
h3 { margin: 0; font-size: 17px; }

.brand-block { min-width: 0; flex: 1; }
.auth-block { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.auth-status {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.66);
  color: var(--muted);
  font-size: 10px;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-btn {
  min-height: 30px;
  border: 0;
  border-radius: 10px;
  padding: 0 10px;
  background: linear-gradient(135deg, var(--accent), #ef8f4e);
  color: #fff8ef;
  font-size: 12px;
}
.topbar-btn.ghost {
  background: linear-gradient(135deg, #6d563e, #8a735a);
}

.play-topbar-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.main-layout {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.tab-panel {
  display: none;
  height: 100%;
}
.tab-panel.active {
  display: block;
}
.scroll-panel {
  overflow: auto;
  padding-bottom: 8px;
}
.game-panel {
  flex-direction: column;
  overflow: hidden;
  gap: 8px;
  padding-bottom: 0;
}
.game-panel.active {
  display: flex;
}

.compact-stats,
.goal-strip,
.bottom-tabs,
.settlement-grid,
.leaderboard-grid,
.stats-grid,
.achievement-grid,
.medal-grid,
.collection-grid,
.shop-grid,
.daily-list,
.modal-actions {
  display: grid;
  gap: 10px;
}

.compact-stats {
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.stat-pill,
.goal-chip,
.board-banner,
.panel-card,
.daily-card,
.task-item,
.cat-card,
.shop-item,
.achievement-item,
.medal-card,
.stats-item,
.leaderboard-card,
.box-result,
.settlement-item {
  border: 1px solid rgba(104, 70, 33, 0.12);
  border-radius: var(--radius-lg);
}

.stat-pill {
  background: rgba(255, 252, 244, 0.88);
  padding: 8px 9px;
  min-height: 48px;
}
.stat-pill span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 4px;
}
.stat-pill strong {
  font-size: 15px;
  line-height: 1;
}

.goal-strip {
  display: none;
}
.goal-chip {
  background: rgba(255, 250, 243, 0.9);
  text-align: center;
  padding: 8px 4px;
  color: var(--muted);
}
.goal-chip strong { display: block; color: var(--ink); }
.goal-chip.reached {
  background: linear-gradient(135deg, rgba(31,138,112,0.18), rgba(245,203,112,0.2));
}

.board-banner {
  display: none;
}

.board-shell-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0 2px;
}
.board-shell {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background:
    linear-gradient(160deg, rgba(154, 118, 79, 0.7), rgba(104, 71, 42, 0.86)),
    var(--board);
  border-radius: 22px;
  padding: var(--tile-gap);
  box-shadow: 0 18px 30px rgba(74, 42, 11, 0.22);
  overflow: hidden;
  touch-action: none;
}
.board-grid, .tile-layer {
  position: absolute;
  inset: var(--tile-gap);
}
.board-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--tile-gap);
}
.board-cell {
  border-radius: 18px;
  background: var(--cell);
}
.tile {
  position: absolute;
  border: 0;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 7vw, 38px);
  font-weight: 700;
  color: #432f1e;
  background: #f5e6cf;
  transition: left 140ms ease, top 140ms ease, transform 160ms ease, opacity 160ms ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.32), 0 10px 18px rgba(53, 28, 8, 0.18);
}
.tile.new { animation: tile-pop 180ms ease; }
.tile.merged { animation: tile-merge 220ms ease; }
.board-shell.sand-mode { outline: 4px solid rgba(64, 92, 245, 0.22); }
.board-shell.sand-mode .board-cell { background: rgba(214, 230, 255, 0.28); }

.skill-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 16px;
  color: #fff8ee;
  background: linear-gradient(180deg, rgba(24, 74, 64, 0.5), rgba(24, 74, 64, 0.16));
  font-weight: 700;
  pointer-events: none;
}

.skill-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.skill-mini {
  min-height: 42px;
  border: 0;
  border-radius: 13px;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #fff9f0;
  box-shadow: 0 14px 24px rgba(66, 47, 29, 0.18);
}
.skill-icon { font-size: 14px; line-height: 1; }
.skill-name { font-size: 9px; font-weight: 700; }
.skill-mini strong { font-size: 11px; }
.skill-clear { background: linear-gradient(135deg, var(--accent), #ef8f4e); }
.skill-sand { background: linear-gradient(135deg, var(--accent-2), #53b899); }
.skill-moon { background: linear-gradient(135deg, var(--accent-3), #7387ff); }
.skill-reset { background: linear-gradient(135deg, #6d563e, #8a735a); }
.skill-mini.disabled { opacity: 0.45; pointer-events: none; }
.skill-mini.active-mode { outline: 3px solid rgba(64,92,245,0.25); transform: translateY(-2px); }

.panel-card, .daily-card {
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head.small { margin-bottom: 10px; }
.helper-text, .date-chip, .task-meta, .collection-meta, .achievement-meta, .leader-meta {
  color: var(--muted);
  font-size: 13px;
}
.date-chip {
  background: rgba(255,255,255,0.65);
  border-radius: 999px;
  padding: 6px 10px;
}

.action-btn {
  min-height: 54px;
  border: 0;
  border-radius: 18px;
  color: #fff9f0;
  background: linear-gradient(135deg, var(--accent), #ef8f4e);
  box-shadow: 0 14px 24px rgba(164,79,33,0.22);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.action-btn.ghost,
.action-btn.compact {
  background: linear-gradient(135deg, #6d563e, #8a735a);
}
.action-btn.disabled,
.task-claim.disabled { opacity: 0.45; pointer-events: none; }

.box-result, .task-item, .shop-item, .achievement-item, .medal-card, .stats-item, .leaderboard-card, .settlement-item {
  background: rgba(255,252,246,0.88);
  padding: 14px;
}

.shop-grid, .collection-grid, .achievement-grid, .medal-grid, .leaderboard-grid, .stats-grid, .daily-list {
  grid-template-columns: 1fr;
}
.shop-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.shop-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: rgba(255,236,208,0.9);
}
.task-claim {
  min-width: 84px;
  min-height: 40px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-3), #6d84ff);
  color: #fff;
}

.cat-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,247,236,0.92));
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.cat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 84px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--cat-accent) 75%, white), rgba(255,255,255,0.35));
  opacity: 0.95;
}
.cat-card > * { position: relative; z-index: 1; }
.cat-art {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 34px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.78);
}
.collection-badge, .achievement-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(217,92,43,0.12);
  color: var(--accent);
  font-size: 12px;
  margin-bottom: 10px;
}
.fragment-bar, .progress-bar {
  height: 8px;
  background: rgba(116,91,64,0.12);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.fragment-fill, .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffb55d, #ff7d4b);
}

.task-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}
.achievement-item.unlocked {
  border-color: rgba(31,138,112,0.24);
  background: linear-gradient(135deg, rgba(234,252,246,0.92), rgba(255,252,246,0.92));
}
.achievement-item.locked,
.cat-card.locked {
  opacity: 0.62;
}

.medal-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.medal-chip {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), 0 10px 18px rgba(61,39,15,0.14);
}
.medal-chip::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.2);
}
.medal-face { font-size: 28px; line-height: 1; }
.medal-chip.bronze { background: linear-gradient(135deg, #a96a3c, #d5a06e); }
.medal-chip.silver { background: linear-gradient(135deg, #95a3b4, #dfe6ef); }
.medal-chip.gold { background: linear-gradient(135deg, #cf9822, #f2dc82); }
.medal-chip.blackGold { background: linear-gradient(135deg, #1f1d1b, #8c7751); }
.medal-chip.bronze .medal-face { filter: sepia(1) hue-rotate(335deg) saturate(2.4) brightness(0.95); }
.medal-chip.silver .medal-face { filter: grayscale(1) brightness(1.2); }
.medal-chip.gold .medal-face { filter: sepia(1) hue-rotate(350deg) saturate(3) brightness(1.05); }
.medal-chip.blackGold .medal-face { filter: grayscale(1) contrast(1.2) brightness(0.72); }

.leaderboard-card h3 { margin: 0 0 8px; font-size: 17px; }
.leaderboard-winner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-size: 15px;
}
.leaderboard-winner strong { font-size: 20px; }

.stats-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.stats-item strong { font-size: 20px; }

.bottom-tabs {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(57,41,27,0.94);
  border-radius: 14px;
  padding: 4px;
  box-shadow: 0 10px 22px rgba(48,28,9,0.22);
  z-index: 3;
  flex-shrink: 0;
}
.tab-btn {
  min-height: 32px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255,245,229,0.7);
  font-size: 11px;
  padding: 0 4px;
}
.tab-btn.active {
  background: linear-gradient(135deg, rgba(255,208,127,0.25), rgba(255,255,255,0.12));
  color: #fff6e8;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(32,22,15,0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal-card {
  width: min(100%, 440px);
  background: linear-gradient(180deg, rgba(255,249,239,0.98), rgba(248,235,214,0.98));
  border-radius: 28px;
  box-shadow: 0 24px 44px rgba(48,28,9,0.3);
  padding: 20px;
}
.login-form {
  display: grid;
  gap: 12px;
}
.login-form label span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-form input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(121,101,82,0.18);
  border-radius: 14px;
  padding: 0 14px;
  background: rgba(255,255,255,0.88);
}
.modal-actions.twin {
  grid-template-columns: 1fr 1fr;
}
.settlement-grid {
  grid-template-columns: repeat(2, 1fr);
  margin: 16px 0;
}
.settlement-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.settlement-item strong { font-size: 20px; }
.reward-note {
  border-radius: 18px;
  background: rgba(255,255,255,0.68);
  color: var(--muted);
  padding: 14px;
  margin-bottom: 14px;
}

.toast-layer {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 10px;
  z-index: 50;
}
.toast {
  background: rgba(47,36,26,0.92);
  color: #fff5e7;
  padding: 12px 16px;
  border-radius: 999px;
  box-shadow: 0 14px 24px rgba(47,36,26,0.22);
  animation: toast-in 220ms ease;
}

.hidden { display: none !important; }

@keyframes tile-pop {
  0% { transform: scale(0.72); }
  100% { transform: scale(1); }
}
@keyframes tile-merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes toast-in {
  0% { opacity: 0; transform: translateY(-10px); }
  100% { opacity: 1; transform: translateY(0); }
}

@media (min-width: 780px) {
  :root {
    --board-size: min(88vw, 420px);
    --topbar-height: 96px;
    --tabs-height: 82px;
  }
  .app-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    gap: 12px;
  }
  .topbar {
    min-height: 96px;
    border-radius: var(--radius-xl);
    padding: 14px 16px;
    gap: 12px;
  }
  .eyebrow { font-size: 11px; letter-spacing: 0.18em; }
  h1 { font-size: 26px; }
  .auth-block { gap: 8px; }
  .auth-status {
    padding: 8px 12px;
    font-size: 12px;
    max-width: none;
  }
  .topbar-btn {
    min-height: 40px;
    border-radius: 14px;
    padding: 0 14px;
    font-size: 14px;
  }
  .scroll-panel {
    padding-bottom: calc(var(--tabs-height) + 12px);
  }
  .game-panel {
    gap: 10px;
    padding-bottom: calc(var(--tabs-height) + 8px);
  }
  .compact-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  .stat-pill {
    padding: 12px;
    min-height: 72px;
  }
  .stat-pill span {
    font-size: 12px;
    margin-bottom: 8px;
  }
  .stat-pill strong {
    font-size: 22px;
  }
  .board-banner {
    padding: 10px 12px;
    font-size: 14px;
  }
  .skill-toolbar {
    gap: 10px;
  }
  .skill-mini {
    min-height: 66px;
    border-radius: 18px;
    padding: 8px 4px;
    gap: 4px;
  }
  .skill-icon { font-size: 20px; }
  .skill-name { font-size: 11px; }
  .skill-mini strong { font-size: 15px; }
  .bottom-tabs {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    border-radius: 24px;
    padding: 10px;
    box-shadow: 0 18px 40px rgba(48,28,9,0.34);
  }
  .tab-btn {
    min-height: 52px;
    border-radius: 18px;
    font-size: 14px;
    padding: 0;
  }
  .shop-grid, .collection-grid, .achievement-grid, .medal-grid, .leaderboard-grid, .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  :root {
    --board-size: min(calc(100vw - 22px), calc(100dvh - 356px), 356px);
  }
  .tile {
    font-size: clamp(20px, 6vw, 28px);
  }
  .board-cell,
  .tile {
    border-radius: 15px;
  }
}
