:root {
  --bg-a: #102e2b;
  --bg-b: #704b35;
  --panel: rgba(255, 252, 241, 0.95);
  --panel-soft: rgba(255, 252, 241, 0.84);
  --ink: #142620;
  --muted: #60746d;
  --line: rgba(20, 38, 32, 0.14);
  --accent: #f2b84b;
  --accent-2: #38a879;
  --danger: #e45a4f;
  --radius: 8px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-a), var(--bg-b));
  overflow-x: hidden;
}

button {
  font: inherit;
}

.tzjt-home-link {
  position: fixed !important;
  top: 12px !important;
  left: 12px !important;
  z-index: 80 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  min-height: 34px !important;
  padding: 7px 11px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255, 255, 255, 0.38) !important;
  background: rgba(10, 25, 24, 0.84) !important;
  color: #fffaf1 !important;
  font: 800 0.78rem/1.1 Inter, Segoe UI, Arial, sans-serif !important;
  text-decoration: none !important;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25) !important;
  backdrop-filter: blur(12px) !important;
}

.tzjt-home-link:hover {
  border-color: rgba(242, 184, 75, 0.9) !important;
}

.adventure-app {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px clamp(10px, 1.6vw, 22px) 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  margin-left: 72px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.brand {
  min-width: 0;
  color: #fffaf1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.26);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.7vw, 3rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.brand p {
  margin: 6px 0 0;
  color: rgba(255, 250, 241, 0.84);
  font-weight: 800;
  font-size: clamp(0.78rem, 1.15vw, 0.95rem);
}

.hud {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: repeat(6, minmax(68px, 1fr));
  gap: 8px;
}

.stat {
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.stat small {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(1rem, 1.7vw, 1.32rem);
  line-height: 1;
  color: var(--ink);
}

.shell {
  display: grid;
  grid-template-columns: minmax(500px, 1fr) minmax(310px, 370px);
  gap: 12px;
  min-height: 0;
}

.stage-panel,
.side-panel {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: var(--panel-soft);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.stage-panel {
  display: grid;
  grid-template-rows: auto auto;
  align-self: start;
}

.canvas-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 0;
  background: #96d1d3;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  cursor: crosshair;
}

.stage-status {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.pill {
  max-width: min(540px, 75%);
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(20, 38, 32, 0.15);
  color: #17312b;
  background: rgba(255, 252, 241, 0.88);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
  font-size: 0.85rem;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 241, 0.96);
}

.move-pad,
.action-pad,
.buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid rgba(20, 38, 32, 0.18);
  border-radius: var(--radius);
  background: #fff9ea;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(20, 38, 32, 0.18);
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.btn:hover { background: #fff1cf; }

.btn:active,
.btn.is-down {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(20, 38, 32, 0.18);
}

.btn.primary {
  background: var(--accent);
  color: #18241e;
}

.btn.danger {
  background: #ffe6df;
  color: #81342d;
}

.icon-btn {
  width: 42px;
  padding: 8px;
  font-size: 1rem;
}

.side-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: var(--panel);
}

.panel-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: 0;
  color: var(--ink);
}

.next-shot {
  padding: 6px 9px;
  border-radius: 999px;
  background: #e8f5ef;
  border: 1px solid rgba(56, 168, 121, 0.24);
  color: #1d5b40;
  font-size: 0.75rem;
  font-weight: 900;
  white-space: nowrap;
}

.board-wrap {
  min-height: 0;
  padding: 12px 14px 10px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.board {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  touch-action: manipulation;
}

.cell {
  aspect-ratio: 1;
  border: 1px solid rgba(20, 38, 32, 0.12);
  border-radius: var(--radius);
  background: #fff7e8;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(20, 38, 32, 0.08), 0 4px 10px rgba(0, 0, 0, 0.07);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.cell:hover { transform: translateY(-1px); }

.cell.selected {
  border-color: rgba(20, 38, 32, 0.78);
  background: #fff0bd;
  transform: translateY(-2px) scale(1.02);
}

.cell.clear {
  animation: pop 180ms ease forwards;
}

.piece {
  width: 68%;
  height: 68%;
  position: relative;
  display: block;
  border-radius: 45% 55% 52% 48%;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.11), inset 6px 7px 0 rgba(255, 255, 255, 0.28);
}

.piece::after {
  content: "";
  position: absolute;
  top: 16%;
  left: 19%;
  width: 24%;
  height: 18%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  transform: rotate(-28deg);
}

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

.reward {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid rgba(20, 38, 32, 0.12);
  background: #fff9ea;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.mini-piece {
  width: 20px;
  height: 20px;
  border-radius: 45% 55% 52% 48%;
  box-shadow: inset -4px -5px 0 rgba(0, 0, 0, 0.11), inset 3px 3px 0 rgba(255, 255, 255, 0.28);
}

.side-foot {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.meter {
  height: 12px;
  border-radius: 999px;
  background: #eadfce;
  overflow: hidden;
  border: 1px solid rgba(20, 38, 32, 0.1);
}

.meter span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 240ms ease;
}

.message {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(7, 25, 22, 0.58);
  backdrop-filter: blur(8px);
}

.overlay.open { display: grid; }

.modal {
  width: min(460px, 100%);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: #fffaf0;
  color: var(--ink);
  padding: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  text-align: center;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 5vw, 2.7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.modal p {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 800;
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.42) rotate(8deg); opacity: 0; }
}

@media (max-width: 1060px) {
  body { overflow-y: auto; }
  .adventure-app { min-height: auto; }
  .topbar {
    margin-left: 0;
    padding-top: 44px;
    grid-template-columns: 1fr;
  }
  .hud {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .shell {
    grid-template-columns: 1fr;
  }
  .side-panel {
    grid-template-rows: auto auto auto;
  }
  .board {
    max-width: 440px;
  }
}

@media (max-width: 640px) {
  .adventure-app {
    padding: 8px;
    gap: 8px;
  }
  .tzjt-home-link {
    top: 8px !important;
    left: 8px !important;
    font-size: 0.72rem !important;
  }
  .brand {
    padding-left: 48px;
    padding-right: 76px;
  }
  .brand h1 {
    font-size: 1.95rem;
  }
  .brand p {
    display: none;
  }
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .stat {
    min-height: 48px;
    padding: 7px 8px;
  }
  .controls {
    grid-template-columns: 1fr;
  }
  .stage-status {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }
  .pill {
    max-width: 100%;
    font-size: 0.76rem;
  }
  .board {
    gap: 5px;
  }
  .reward-map {
    grid-template-columns: 1fr;
  }
  .panel-head {
    grid-template-columns: 1fr;
  }
  #tzjt-language-toggle {
    top: 8px !important;
    right: 8px !important;
    bottom: auto !important;
  }
}

@media (max-width: 380px) {
  .brand h1 {
    font-size: 1.62rem;
  }
  .brand {
    padding-left: 42px;
    padding-right: 72px;
  }
}
