* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0f1720; color: #e8eef5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas { display: block; touch-action: none; }
.hidden { display: none !important; }

button {
  font: inherit; color: inherit; cursor: pointer;
  background: #2b6e4f; border: 0; border-radius: 12px; padding: 12px 18px;
}
button.secondary { background: #2a3746; }
button:disabled { opacity: .35; cursor: default; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.top {
  display: flex; align-items: flex-start; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
}
.stat { min-width: 64px; }
.stat small { display: block; font-size: 11px; opacity: .6; text-transform: uppercase; letter-spacing: .08em; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat.right { text-align: right; }
#chain {
  flex: 1; text-align: center; font-size: clamp(22px, 6vw, 36px); font-weight: 800;
  letter-spacing: .12em; min-height: 1.3em; overflow-wrap: anywhere;
  text-shadow: 0 2px 8px #000a;
}
#chain .scored { color: #f2c14e; }
#chain .pending { color: #e8eef5; }
#chain .hint { font-size: 14px; font-weight: 400; letter-spacing: 0; opacity: .45; }
#chain.shake { animation: shake .35s; }
@keyframes shake {
  20% { transform: translateX(-8px); color: #ff6b6b; }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
#recent {
  position: absolute; left: 12px; top: calc(env(safe-area-inset-top) + 70px);
  display: flex; flex-direction: column; gap: 6px;
}
.chip {
  background: #0f1720cc; border: 1px solid #2a3746; border-radius: 10px;
  padding: 4px 10px; font-size: 14px; display: flex; gap: 8px; animation: pop .3s;
}
.chip.new { border-color: #3fbf7f; }
.chip span { color: #f2c14e; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#bank {
  position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 96px; height: 96px; border-radius: 50%; font-weight: 800; letter-spacing: .05em;
  background: #2a3746; box-shadow: 0 4px 16px #0008;
}
#bank.ready { background: #c8962a; color: #1a1205; }
#pause-btn {
  position: absolute; left: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 48px; height: 48px; border-radius: 50%; background: #2a3746cc; padding: 0;
}

/* Overlays */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: #0f1720b0; backdrop-filter: blur(3px); padding: 16px;
}
.panel {
  max-width: 420px; width: 100%; background: #16212d; border: 1px solid #2a3746;
  border-radius: 18px; padding: 24px; box-shadow: 0 10px 40px #0009;
}
h1 { margin: 0 0 12px; font-size: 40px; letter-spacing: .02em; }
h1 span { color: #3fbf7f; }
h2 { margin: 0 0 12px; }
p { line-height: 1.45; }
.small { font-size: 14px; opacity: .8; }
.tiny { font-size: 12px; opacity: .45; margin-bottom: 0; }
.buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.buttons small { display: block; font-size: 12px; opacity: .7; }
.grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.grid b { text-align: right; }
.fatal { position: fixed; bottom: 0; left: 0; right: 0; background: #400; color: #fff; padding: 12px; margin: 0; }

/* Speed buttons and help */
.speed {
  position: absolute; left: 16px; width: 48px; height: 48px; border-radius: 50%;
  background: #2a3746cc; padding: 0; touch-action: none;
}
#boost { bottom: calc(env(safe-area-inset-bottom) + 144px); }
#brake { bottom: calc(env(safe-area-inset-bottom) + 84px); }
.panel.help { max-height: calc(100vh - 32px); overflow-y: auto; }
.help h3 { margin: 14px 0 2px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: #3fbf7f; }
.help p { margin: 4px 0; font-size: 14px; }
.gold { color: #f2c14e; font-weight: 700; }
.white { font-weight: 700; }

/* Word card */
#card {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 64px); width: min(94vw, 440px);
  background: #16212de6; border: 1px solid #2a3746; border-radius: 14px;
  padding: 10px 14px; pointer-events: none; box-shadow: 0 6px 24px #0008;
  animation: pop .25s;
}
#card .head { display: flex; align-items: baseline; gap: 10px; }
#card .head b { font-size: 20px; letter-spacing: .06em; text-transform: uppercase; }
#card .pts { color: #f2c14e; font-weight: 700; }
#card .new { color: #7dffb2; font-size: 12px; border: 1px solid #3fbf7f; border-radius: 8px; padding: 0 6px; }
#card .rel { font-size: 13px; opacity: .75; margin-top: 2px; }
#card ol { margin: 6px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.35; }
#card li em { color: #3fbf7f; font-style: normal; font-size: 12px; }
#recent { left: auto; right: 12px; align-items: flex-end; top: calc(env(safe-area-inset-top) + 215px); }
.tiny a { color: inherit; }
code { font-size: 12px; background: #0f1720; padding: 1px 5px; border-radius: 5px; }
#card .spell { color: #9fb3c8; font-size: 14px; font-style: italic; }

/* Languages, challenge, toast, collection, settings */
.label { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .6; }
.langs { display: flex; flex-wrap: wrap; gap: 6px; }
.langs button { padding: 8px 12px; border-radius: 20px; background: #2a3746; font-size: 14px; }
.langs button.on { background: #2b6e4f; }
.langs button.loading { opacity: .5; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row3 button { padding: 10px 6px; font-size: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; opacity: .85; }
#challenge {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 56px);
  display: flex; align-items: center; gap: 8px; max-width: 90vw;
  background: #0f1720cc; border: 1px solid #5a4a1a; border-radius: 16px; padding: 3px 6px 3px 12px;
}
#challenge small { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #f2c14e; opacity: .85; }
#challenge b { letter-spacing: .12em; font-size: 15px; }
#challenge .have { color: #f2c14e; }
#ch-pts { color: #f2c14e; font-size: 13px; font-weight: 700; }
#ch-skip { pointer-events: auto; padding: 2px 8px; border-radius: 12px; background: #2a3746; font-size: 14px; }
#challenge.done { animation: cdone .8s; }
@keyframes cdone { 30% { background: #7a5d10; transform: translateX(-50%) scale(1.15); } }
#netinfo { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 92px); font-size: 11px; opacity: .55; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 130px);
  background: #16212df0; border: 1px solid #2a3746; border-radius: 12px; padding: 8px 14px; font-size: 14px; z-index: 5; pointer-events: none;
}
#card { top: calc(env(safe-area-inset-top) + 118px); }
.filters { display: flex; gap: 8px; margin: 8px 0; }
input[type=search], input[type=text], select {
  font: inherit; color: inherit; background: #0f1720; border: 1px solid #2a3746; border-radius: 10px; padding: 8px 10px;
}
.filters input { flex: 1; min-width: 0; }
input[type=text] { width: 100%; margin-bottom: 8px; }
#col-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; max-height: 34vh; overflow-y: auto; }
.colrow { padding: 4px 9px; border-radius: 8px; background: #22303f; font-size: 13px; text-transform: lowercase; }
.colrow.more { background: transparent; opacity: .7; }
#col-detail { min-height: 3.5em; background: #0f1720; border-radius: 10px; padding: 8px 10px; }
#col-detail:empty { display: none; }
.wrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.wrow > span { width: 56px; opacity: .6; }
.chipbtn { padding: 4px 10px; border-radius: 14px; background: #22303f; font-size: 13px; border: 2px solid; }
.chipbtn.on { background: #2b6e4f; }

#challenge { overflow: hidden; }
#ch-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: #f2c14e; transition: width .2s linear; }
#challenge.low #ch-bar { background: #ff6b6b; }
#challenge.low { border-color: #7a2a2a; }
button.secondary small { opacity: .6; }

.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.row4 button { padding: 10px 4px; font-size: 13px; }
#rk-list { margin: 8px 0; max-height: 46vh; overflow-y: auto; }
.rk { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 14px; }
.rk:nth-child(odd) { background: #1b2733; }
.rk.me { background: #2b6e4f; }
.rk.gap { display: block; text-align: center; opacity: .5; padding: 0; }
#rk-note { margin: 0; }
.filters select { flex: 1; min-width: 0; }

/* Answer bar (spaced repetition): small and quiet, at the bottom, keys 1-4 */
#rate {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 6;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: #0f1720b0; font-size: 12px;
}
#rate button { background: #22303f; padding: 4px 8px; border-radius: 8px; font-size: 12px; opacity: .8; display: flex; gap: 5px; align-items: center; }
#rate button:hover { opacity: 1; }
#rate kbd { font: inherit; font-size: 11px; background: #3a4b5e; border-radius: 4px; padding: 0 5px; }
#rate .g0 kbd { background: #7a3b3b; } #rate .g2 kbd { background: #2b6e4f; } #rate .g3 kbd { background: #2b6e8f; }
#rate .rated { padding: 3px 8px; opacity: .9; } #rate .g0.rated { color: #ffb3b3; } #rate .g1.rated, #rate .g2.rated, #rate .g3.rated { color: #8fe3b4; }
@media (max-width: 600px) { #rate { left: 72px; transform: none; bottom: calc(env(safe-area-inset-bottom) + 20px); max-width: calc(100vw - 72px - 122px); flex-wrap: wrap; } }
#challenge #ch-clue { font-size: 12px; opacity: .8; margin-left: 6px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#challenge .hidden-letters { opacity: .55; letter-spacing: .15em; }

/* start screen: Learn is the main button */
.buttons button.big { padding: 18px 16px; font-size: 20px; background: #2b6e4f; }
.buttons button.big small { font-size: 12px; font-weight: 400; opacity: .85; }
.row4 { grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); }
/* look screen */
#look-canvas { display: block; width: 100%; max-width: 360px; height: auto; margin: 6px auto; border-radius: 12px; border: 1px solid #2a3746; }
.chipbtn.locked { opacity: .45; }

.langgroups details { margin: 4px 0; }
.langgroups summary { cursor: pointer; font-size: 13px; color: #9fb3c8; padding: 4px 0; }
.langgroups .langs { padding: 2px 0 6px; }
.langs button.dim { opacity: .6; border: 1px dashed #4a5a6c; }
#mylang button.on { background: #2b6e4f; }

.credit { margin: 8px 0; padding-bottom: 6px; border-bottom: 1px solid #22303f; }

.help details { margin: 6px 0; border-bottom: 1px solid #22303f; padding-bottom: 4px; }
.help summary { cursor: pointer; font-weight: 700; color: #3fbf7f; padding: 6px 0; }
.help details p { margin: 4px 0 8px; }
.essentials { margin: 6px 0; padding-left: 18px; font-size: 14px; line-height: 1.4; color: #c4d2e0; }
.essentials li { margin-bottom: 4px; }
