:root {
  --ink: #07080d;
  --panel: #121722;
  --ivory: #f6e7c1;
  --muted: #b7ad98;
  --gold: #f2c14e;
  --gold-deep: #a67c1d;
  --line: rgba(242, 193, 78, 0.42);
  --sapphire: #1d4e9f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
}

body {
  font-family: "Noto Sans Devanagari", "Noto Sans", "Kohinoor Devanagari", "Kohinoor", sans-serif;
  color: var(--ivory);
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(29, 78, 159, 0.5), transparent 62%),
    radial-gradient(420px 240px at 100% 100%, rgba(242, 193, 78, 0.1), transparent 55%),
    #05060a;
}

button, input { font: inherit; color: inherit; }

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

img { max-width: 100%; display: block; }

#shell {
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(14, 18, 30, 0.98), rgba(5, 6, 10, 0.98));
  box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.2);
}

#view {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 12px 8px;
}

#view.play-mode {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px;
}

h1, h2, p { margin: 0; overflow-wrap: break-word; }

h1 {
  font-size: clamp(1.45rem, 5.4vw, 2rem);
  line-height: 1.2;
  font-weight: 750;
}

h2 {
  font-size: clamp(1.15rem, 4.4vw, 1.4rem);
  line-height: 1.25;
}

.brand {
  margin: 0 0 2px;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
}

.lead, .copy {
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.98rem;
}

.mast {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mast > div { min-width: 0; }

.crest {
  width: 68px;
  height: 68px;
  object-fit: cover;
  flex: 0 0 auto;
  border: 1px solid var(--line);
}

.bulbs {
  height: 10px;
  width: 100%;
  margin: 8px 0;
  background-image: radial-gradient(circle, #ffe7a3 1.4px, transparent 2.2px);
  background-size: 14px 10px;
  background-repeat: repeat-x;
  filter: drop-shadow(0 0 4px rgba(242, 193, 78, 0.75));
}

.hero-shot, .world-shot {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
}

.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.plate {
  min-width: 0;
  padding: 12px;
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(36, 84, 176, 0.28), transparent 48%),
    linear-gradient(180deg, #161b28, #0b0e16);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.actions, .split {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.actions > *, .split > * { flex: 1; min-width: 0; }

.action, .tool, .level-dot, .nav-btn {
  min-width: 0;
}

.action {
  min-height: 46px;
  padding: 10px 12px;
  line-height: 1.2;
  white-space: normal;
  font-weight: 700;
}

.action.primary {
  color: #1a1303;
  background: linear-gradient(180deg, #ffe7a8, #e2b340 46%, #a67c1d);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 3px 0 #6d5010;
}

.action.ghost, .tool, .level-dot {
  color: var(--ivory);
  border: 1px solid var(--line);
  background: rgba(8, 10, 16, 0.45);
}

.action:active, .tool:active { transform: translateY(1px); }

.stat-row, .goal-row, .tool-row, .level-row, .mech-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.stat, .goal, .tool {
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  font-size: 0.84rem;
  line-height: 1.2;
}

.goal { border-left-width: 4px; }
.goal.sapphire { border-left-color: #60a5fa; }
.goal.gold { border-left-color: #f2c14e; }
.goal.emerald { border-left-color: #34d399; }
.goal.ruby { border-left-color: #fb7185; }
.goal.amethyst { border-left-color: #c084fc; }
.goal.done { color: #d9ffe8; border-color: rgba(52, 211, 153, 0.7); }

.tool { flex: 1; font-weight: 650; }
.tool.warn { color: #ffb4c0; }

.world-card { display: flex; flex-direction: column; gap: 10px; }
.world-card.sealed { opacity: 0.72; }
.world-card header { display: flex; flex-direction: column; gap: 4px; }

.level-dot {
  width: calc(33.33% - 6px);
  min-height: 74px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

.level-dot strong { font-size: 0.78rem; font-weight: 700; line-height: 1.25; }
.level-dot:disabled { opacity: 0.38; cursor: default; }
.level-dot.now { box-shadow: inset 0 0 0 1px var(--gold); }

.pips { display: flex; gap: 4px; }
.pip {
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border: 1px solid var(--gold);
  display: inline-block;
}
.pip.on { background: var(--gold); box-shadow: 0 0 6px rgba(242, 193, 78, 0.8); }

.mech {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: center;
}
.mech p { font-size: 0.92rem; }

.sample {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 30%;
  position: relative;
  box-shadow: inset 0 -6px 8px rgba(0, 0, 0, 0.35);
}
.sample.sapphire { background: radial-gradient(circle at 32% 28%, #e7f1ff, #3b82f6 36%, #123a86 72%, #071433); }
.sample.gold { background: radial-gradient(circle at 32% 28%, #fff6d4, #f2c14e 38%, #a16207 74%, #3f2a06); }
.sample.amethyst { background: radial-gradient(circle at 32% 28%, #f3e8ff, #a855f7 40%, #581c87 74%, #2e1065); }
.sample.echo::after, .sample.prism::after, .sample.key::after {
  content: "";
  position: absolute;
}
.sample.echo::after {
  left: 12%; right: 12%; top: 44%; height: 12%;
  background: #fff6d2;
}
.sample.prism::after {
  width: 34%; height: 34%; left: 33%; top: 33%;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #fff, #f2c14e 40%, #93c5fd);
}
.sample.key::after {
  width: 46%; height: 46%; left: 27%; top: 27%;
  border-radius: 50%;
  border: 2px solid #fff1c2;
}

.relic {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}
.relic img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  flex: 0 0 auto;
  border: 1px solid var(--line);
}
.relic.locked img { filter: grayscale(1) brightness(0.45); }
.relic div { min-width: 0; }
.relic h2 { font-size: 1.02rem; }
.progress-note { color: var(--gold); font-size: 0.82rem; margin-top: 4px; }

.play {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.play-bg, .play-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.play-bg { background-size: cover; background-position: center; opacity: 0.38; }
.play-shade { background: linear-gradient(180deg, rgba(5, 6, 10, 0.5), rgba(5, 6, 10, 0.9)); }

.play-ui {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.play-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.play-top .titles { flex: 1; min-width: 0; }
.level-name, .world-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.level-name { font-weight: 750; font-size: 1rem; }
.world-name { color: var(--muted); font-size: 0.78rem; }

.move-disc {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff4cc, #e4b445 42%, #8a6416);
  color: #1a1303;
  font-weight: 800;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 0 0 3px #3a2a0c;
}
.move-disc.low {
  background: radial-gradient(circle at 35% 30%, #ffe4ea, #e11d48 46%, #7f1d1d);
  color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 0 0 3px #4c0519;
}
.move-caption { font-size: 0.68rem; color: var(--muted); text-align: center; }

.coach {
  font-size: 0.84rem;
  line-height: 1.35;
  color: #1a1303;
  background: #f2c14e;
  padding: 8px;
  font-weight: 700;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  background: transparent;
}

.board {
  display: grid;
  touch-action: none;
  user-select: none;
}

.cell {
  display: grid;
  place-items: center;
  background: rgba(5, 8, 16, 0.78);
  border-radius: 8px;
  padding: 0;
}
.cell.void { background: transparent; pointer-events: none; }
.cell.flash { background: rgba(255, 224, 138, 0.28); }

.gem-face {
  width: 84%;
  height: 84%;
  border-radius: 30%;
  position: relative;
  box-shadow: inset 0 -7px 8px rgba(0, 0, 0, 0.35), 0 0 10px var(--glow, transparent);
}
.cell.sapphire .gem-face { background: radial-gradient(circle at 32% 28%, #e7f1ff, #3b82f6 34%, #123a86 70%, #071433); --glow: rgba(96, 165, 250, 0.85); }
.cell.gold .gem-face { background: radial-gradient(circle at 32% 28%, #fff6d4, #f2c14e 36%, #a16207 72%, #3f2a06); --glow: rgba(242, 193, 78, 0.8); }
.cell.emerald .gem-face { background: radial-gradient(circle at 32% 28%, #d1fae5, #34d399 36%, #047857 72%, #022c22); --glow: rgba(52, 211, 153, 0.75); }
.cell.ruby .gem-face { background: radial-gradient(circle at 32% 28%, #ffe4e6, #fb7185 36%, #be123c 72%, #4c0519); --glow: rgba(251, 113, 133, 0.75); }
.cell.amethyst .gem-face { background: radial-gradient(circle at 32% 28%, #f3e8ff, #c084fc 36%, #6b21a8 72%, #2e1065); --glow: rgba(192, 132, 252, 0.8); }

.mark, .seal { display: none; position: absolute; }
.cell.echo .mark, .cell.prism .mark, .cell.key .mark, .cell.locked .seal { display: block; }
.cell.echo .mark { left: 12%; right: 12%; top: 44%; height: 12%; background: #fff6d2; box-shadow: 0 0 8px #ffe08a; }
.cell.echo.v .mark { left: 44%; right: auto; top: 12%; bottom: 12%; width: 12%; height: auto; }
.cell.prism .mark {
  width: 34%; height: 34%; left: 33%; top: 33%;
  background: linear-gradient(135deg, #fff, #f2c14e 42%, #93c5fd);
  transform: rotate(45deg);
}
.cell.key .mark {
  width: 44%; height: 44%; left: 28%; top: 28%;
  border-radius: 50%;
  border: 2px solid #fff1c2;
  box-shadow: inset 0 0 0 3px rgba(7, 8, 13, 0.5);
}
.cell.locked .gem-face { filter: saturate(0.25) brightness(0.62); }
.cell.locked .seal {
  inset: 16%;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(5, 6, 10, 0.5);
}
.cell.selected .gem-face { outline: 2px solid #ffe7a8; outline-offset: 1px; transform: scale(1.06); }
.cell.hint .gem-face { animation: hint 0.7s ease-in-out infinite; }
.cell.pop .gem-face { animation: burst 0.16s ease-in forwards; }
.gem-face.falling { animation: fall 0.2s ease-in; }
.gem-face.born { animation: born 0.2s ease-out; }

@keyframes hint { 50% { box-shadow: 0 0 0 3px #f2c14e, 0 0 12px rgba(242, 193, 78, 0.8); } }
@keyframes burst { to { transform: scale(0.12); opacity: 0; } }
@keyframes fall { from { transform: translateY(calc(var(--drop) * var(--step) * -1px)); } }
@keyframes born { from { transform: scale(0.3); opacity: 0.2; } }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  place-items: center;
  padding: 10px;
  background: rgba(5, 6, 10, 0.74);
}
.overlay.on { display: grid; }
.overlay .plate {
  width: min(100%, 440px);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 6;
  transform: translateX(-50%);
  max-width: calc(100% - 20px);
  background: var(--gold);
  color: #1a1303;
  font-size: 0.8rem;
  font-weight: 750;
  padding: 7px 10px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}
.toast.on { opacity: 1; }

#nav {
  flex: 0 0 auto;
  background: #07080d;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.nav-btn {
  min-height: 54px;
  padding: 6px 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
}
.nav-btn span {
  font-size: 0.68rem;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diamond {
  width: 13px;
  height: 13px;
  transform: rotate(45deg);
  border: 1px solid rgba(242, 193, 78, 0.75);
}
.nav-btn.active { color: var(--gold); }
.nav-btn.active .diamond {
  background: linear-gradient(135deg, #dbeafe, #1d4e9f 42%, #f2c14e);
  box-shadow: 0 0 10px rgba(242, 193, 78, 0.9);
}

button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (min-width: 480px) {
  .crest { width: 84px; height: 84px; }
  #view { padding: 16px 16px 10px; }
  .level-dot strong { font-size: 0.86rem; }
}

@media (max-height: 640px) {
  .crest { width: 52px; height: 52px; }
  .nav-btn { min-height: 48px; }
  .coach { font-size: 0.76rem; padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.hint .gem-face,
  .cell.pop .gem-face,
  .gem-face.falling,
  .gem-face.born { animation: none; }
}
