:root {
  --bg: #070912;
  --ink: #e8ecf8;
  --dim: #8a93ad;
  --accent: #ffb13d;
  --panel: #0d1120;
  --line: #232a42;
  --spark: #ffb13d;
  --bramble: #5dd97c;
  --sap: #e8c468;
  --frost: #7ed4ff;
  --pollen: #ff7edb;
  --echo: #b89cff;
  --void: #4a5168;
  --seed: #fff7d6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: crosshair;
}

/* HUD */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  pointer-events: none;
  z-index: 5;
}
#hud-left, #hud-right { display: flex; align-items: center; gap: 8px; }
#hud-right { pointer-events: auto; }

#logo {
  font-weight: 800;
  letter-spacing: 0.22em;
  font-size: 15px;
  color: var(--ink);
}
#mode-tag {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

#hud-score {
  position: absolute;
  left: 50%;
  top: calc(8px + env(safe-area-inset-top));
  transform: translateX(-50%);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#score {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 0 18px rgba(255,177,61,0.35);
}
#score.bump { animation: bump 0.18s ease; }
@keyframes bump { 50% { transform: scale(1.18); } }
#mult {
  display: block;
  font-size: 11px;
  color: var(--pollen);
  letter-spacing: 0.1em;
  min-height: 14px;
}

.chip {
  pointer-events: auto;
  background: rgba(13,17,32,0.82);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--dim); }
.chip.icon { width: 30px; height: 30px; padding: 0; text-align: center; }
.chip.active { border-color: var(--accent); color: var(--accent); }

#hud-bottom {
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  color: var(--dim);
  pointer-events: none;
  z-index: 5;
  letter-spacing: 0.04em;
}
#style-name { color: var(--echo); font-style: italic; }

#goalbar {
  width: 150px;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  margin: 5px auto 0;
}
#goalbar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.15s;
}

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 9;
}
#flash.go { animation: flashanim 0.55s ease-out; }
@keyframes flashanim { 0% { opacity: 0.5; } 100% { opacity: 0; } }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(52px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(13,17,32,0.94);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 20;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,6,12,0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 18px;
}
.overlay.hidden { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px;
  max-width: 430px;
  width: 100%;
  text-align: center;
}
.panel.scroll {
  max-height: 86vh;
  overflow-y: auto;
  text-align: left;
}
.panel.scroll h2 { font-size: 15px; margin: 18px 0 6px; color: var(--accent); }
.panel.scroll h2:first-child { margin-top: 0; }
.panel.scroll p { font-size: 13.5px; line-height: 1.55; color: var(--ink); margin: 6px 0; }

.panel h1 {
  margin: 0;
  font-size: 44px;
  letter-spacing: 0.3em;
  padding-left: 0.3em;
  font-weight: 800;
  text-shadow: 0 0 30px rgba(255,177,61,0.4);
}
.panel h2 { margin: 0 0 10px; font-size: 20px; }
.sub {
  margin: 4px 0 14px;
  color: var(--dim);
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.tag { font-size: 16px; line-height: 1.5; margin: 0 0 14px; }
.goal { line-height: 1.9; }
.goal .d { margin: 0 1px; vertical-align: baseline; }
.c-spark { color: var(--spark); }
.c-bramble { color: var(--bramble); }
.hint { font-size: 13px; color: var(--dim); line-height: 1.55; margin: 0 0 18px; }
.fine { font-size: 11px; color: var(--dim); margin: 14px 0 0; opacity: 0.8; }

.steps {
  list-style: none;
  padding: 0;
  margin: 0 auto 20px;
  max-width: 330px;
  text-align: left;
}
.steps li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.45;
  padding: 6px 0;
  color: var(--ink);
}
.steps .d { margin-top: 4px; }
.steps b { color: var(--accent); }

#hint {
  position: fixed;
  left: 50%;
  bottom: calc(40px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(86vw, 480px);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(4,6,12,0.9);
  background: rgba(13,17,32,0.66);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 16px;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.3s;
}
#hint:empty { display: none; }

button.big {
  background: var(--accent);
  color: #1a1206;
  border: 0;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 30px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.04em;
  -webkit-tap-highlight-color: transparent;
}
button.big:hover { filter: brightness(1.08); }
button.ghost {
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 13px;
  margin-top: 12px;
  cursor: pointer;
  display: block;
  width: 100%;
}
.row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }

/* legend */
#legend { list-style: none; padding: 0; margin: 8px 0; }
#legend li { font-size: 13px; padding: 4px 0; color: var(--ink); display: flex; align-items: center; gap: 9px; }
#legend b { color: var(--ink); }
.d {
  width: 11px; height: 11px; border-radius: 50%; flex: 0 0 11px;
  display: inline-block;
}
.d.spark   { background: var(--spark);   box-shadow: 0 0 8px var(--spark); }
.d.bramble { background: var(--bramble); box-shadow: 0 0 8px var(--bramble); }
.d.sap     { background: var(--sap);     box-shadow: 0 0 8px var(--sap); }
.d.frost   { background: var(--frost);   box-shadow: 0 0 8px var(--frost); }
.d.pollen  { background: var(--pollen);  box-shadow: 0 0 8px var(--pollen); }
.d.echo    { background: var(--echo);    box-shadow: 0 0 8px var(--echo); }
.d.void    { background: #11141f; border: 1px solid var(--void); }
.d.seed    { background: var(--seed);    box-shadow: 0 0 8px var(--seed); }

/* result */
#res-score {
  font-size: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 28px rgba(255,177,61,0.45);
  margin: 6px 0;
}
#res-detail { color: var(--dim); font-size: 13px; min-height: 18px; margin: 0 0 12px; }
#res-glyph {
  font-size: 15px;
  line-height: 1.15;
  letter-spacing: 1px;
  margin: 0 0 16px;
  white-space: pre;
  font-family: ui-monospace, monospace;
}

@media (max-width: 540px) {
  #btn-commons, #btn-hex { font-size: 11px; padding: 5px 9px; }
  .panel h1 { font-size: 36px; }
  #score { font-size: 22px; }
  #hud-score { top: calc(46px + env(safe-area-inset-top)); }
}
