/* БАЗАР design tokens — «ИнвестСлова» */
:root {
  --bazar-lime: #adff00;
  --bazar-lime-hover: #9eeb00;
  --bazar-lime-active: #8fd600;
  --bazar-lime-soft: rgba(173, 255, 0, 0.18);
  --bazar-black: #000000;
  --bazar-text: #111111;
  --bazar-text-secondary: #6b6b6b;
  --bazar-muted: #8a8a8a;
  --bazar-bg: #f6f6f6;
  --bazar-surface: #ffffff;
  --bazar-border: rgba(0, 0, 0, 0.08);
  --bazar-border-strong: rgba(0, 0, 0, 0.12);
  --bazar-green: #60b900;
  --bazar-red: #ff4545;
  --bazar-amber: #e6a700;
  --tile-correct: #60b900;
  --tile-present: #e6a700;
  --tile-absent: #9a9a9a;
  --bazar-radius-sm: 11px;
  --bazar-radius-md: 16px;
  --bazar-radius-lg: 24px;
  --bazar-radius-pill: 99px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --control-min: 48px;
  --font-display: "Montserrat", "Golos Text", system-ui, sans-serif;
  --font-body: "Roboto", "Golos Text", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bazar-bg);
  color: var(--bazar-text);
  font-family: var(--font-body);
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 0;
  position: relative;
  background: var(--bazar-surface);
  box-shadow: 0 0 0 1px var(--bazar-border);
}

/* ——— Top bar ——— */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 0.5px solid var(--bazar-border);
  z-index: 2;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bazar-lime);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-sub {
  font-size: 12px;
  color: var(--bazar-text-secondary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.hud-scores {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.score-pill {
  background: var(--bazar-bg);
  border: 0.5px solid var(--bazar-border);
  border-radius: var(--bazar-radius-pill);
  padding: 6px 10px;
  min-width: 52px;
  text-align: center;
}

.score-pill .label {
  display: block;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bazar-muted);
  line-height: 1.1;
}

.score-pill .value {
  display: block;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.score-pill.record .value {
  color: var(--bazar-green);
}

/* ——— Main stage ——— */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  margin: 8px 12px 0;
  border-radius: var(--bazar-radius-lg);
  border: 0.5px solid var(--bazar-border-strong);
  background: var(--bazar-bg);
  overflow: hidden;
}

.play-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 0;
}

.play-panel[hidden] {
  display: none !important;
}

.status-line {
  margin: 0 0 6px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: #3d5c00;
  background: var(--bazar-lime-soft);
  border-radius: var(--bazar-radius-md);
  padding: 8px 12px;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-line[hidden] {
  display: none !important;
}

.status-main {
  font-size: 12px;
}

.status-pattern {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--bazar-black);
  font-variant-numeric: tabular-nums;
}

.message {
  min-height: 1.2em;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--bazar-text-secondary);
  margin: 0 0 6px;
}

.message-error {
  color: var(--bazar-red);
  font-weight: 600;
}

.board {
  flex: 0 1 auto;
  max-height: min(42vh, 320px);
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
}

.board-placeholder {
  margin: auto;
  padding: 24px;
  text-align: center;
  color: var(--bazar-muted);
  font-size: 14px;
  line-height: 1.4;
}

.board-row {
  display: grid;
  gap: 4px;
  width: max-content;
  max-width: 100%;
  justify-content: center;
  margin: 0 auto;
}

.board-long .board-row {
  gap: 3px;
}

.tile {
  width: var(--tile, 40px);
  height: var(--tile, 40px);
  min-width: var(--tile, 40px);
  min-height: var(--tile, 40px);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--tile, 40px) * 0.42);
  border-radius: 8px;
  border: 1.5px solid var(--bazar-border-strong);
  background: var(--bazar-surface);
  color: var(--bazar-black);
  text-transform: uppercase;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tile-empty {
  background: var(--bazar-surface);
}

.tile-typed {
  border-color: var(--bazar-black);
  animation: pop 0.08s ease;
}

.tile-locked {
  background: var(--bazar-lime-soft);
  border-color: var(--bazar-lime-active);
  color: #3d5c00;
}

.tile-correct {
  background: var(--tile-correct);
  border-color: var(--tile-correct);
  color: #fff;
}

.tile-present {
  background: var(--tile-present);
  border-color: var(--tile-present);
  color: #fff;
}

.tile-absent {
  background: var(--tile-absent);
  border-color: var(--tile-absent);
  color: #fff;
}

@keyframes pop {
  from {
    transform: scale(0.92);
  }
  to {
    transform: scale(1);
  }
}

/* Hints */
.hint-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 6px 0 8px;
}

.hint-bar[hidden] {
  display: none !important;
}

.btn-hint {
  appearance: none;
  border: 0.5px solid var(--bazar-border-strong);
  background: var(--bazar-surface);
  color: var(--bazar-text);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--bazar-radius-pill);
  cursor: pointer;
  min-height: 36px;
  transition: background 0.12s ease, opacity 0.12s ease;
}

.btn-hint:hover:not(:disabled) {
  background: var(--bazar-lime-soft);
}

.btn-hint:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Keyboard — stick to bottom of stage */
.keyboard {
  flex: 0 0 auto;
  margin-top: auto;
  padding: 6px 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: linear-gradient(to top, var(--bazar-bg) 70%, transparent);
}

.keyboard[hidden] {
  display: none !important;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.kb-key {
  appearance: none;
  border: none;
  background: #e4e4e4;
  color: var(--bazar-black);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  min-width: 0;
  flex: 1 1 0;
  max-width: 36px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s ease, transform 0.08s ease;
}

.kb-key:active {
  transform: scale(0.96);
}

.kb-wide {
  flex: 1.55 1 0;
  max-width: 56px;
  font-size: 11px;
}

.kb-correct {
  background: var(--tile-correct);
  color: #fff;
}

.kb-present {
  background: var(--tile-present);
  color: #fff;
}

.kb-absent {
  background: #c8c8c8;
  color: #666;
}

/* Info FAB */
.btn-info-fab {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bazar-lime);
  color: var(--bazar-black);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  font-style: italic;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 4;
}

.btn-info-fab[hidden] {
  display: none !important;
}

/* Overlays — fully cover stage so board/keyboard don't poke through */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  text-align: center;
  background: rgba(246, 246, 246, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
  overflow-y: auto;
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  width: 100%;
  max-width: 320px;
  background: var(--bazar-surface);
  border: 0.5px solid var(--bazar-border);
  border-radius: var(--bazar-radius-lg);
  padding: 24px 20px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

.overlay-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin: 0 auto 12px;
  overflow: hidden;
  background: var(--bazar-lime);
}

.overlay-logo img {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(22px, 6vw, 26px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.overlay .eyebrow {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bazar-text-secondary);
  margin: 0 0 6px;
}

.overlay .tagline {
  margin: 0 0 16px;
  color: var(--bazar-text-secondary);
  font-size: 14px;
  line-height: 1.45;
}

.topic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 0 0 14px;
}

.topic-chip {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--bazar-radius-pill);
  background: var(--bazar-lime-soft);
  color: #3d5c00;
}

.diff-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 0 0 16px;
  flex-wrap: wrap;
}

.btn-diff {
  appearance: none;
  border: 0.5px solid var(--bazar-border-strong);
  background: var(--bazar-bg);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--bazar-radius-pill);
  cursor: pointer;
  min-height: 40px;
}

.btn-diff.is-active {
  background: var(--bazar-lime);
  border-color: transparent;
}

.btn-primary {
  appearance: none;
  border: none;
  background: var(--bazar-lime);
  color: var(--bazar-black);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  padding: 0 28px;
  min-height: var(--control-min);
  border-radius: var(--bazar-radius-pill);
  cursor: pointer;
  width: 100%;
  transition: background 0.12s ease, transform 0.12s ease;
}

.btn-primary:hover {
  background: var(--bazar-lime-hover);
}

.btn-primary:active {
  background: var(--bazar-lime-active);
  transform: scale(0.98);
}

.btn-secondary {
  appearance: none;
  border: 0.5px solid var(--bazar-border-strong);
  background: var(--bazar-surface);
  color: var(--bazar-text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  padding: 0 20px;
  min-height: 44px;
  border-radius: var(--bazar-radius-pill);
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.btn-ghost-info {
  appearance: none;
  border: none;
  background: var(--bazar-lime-soft);
  color: #3d5c00;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  padding: 0 20px;
  min-height: 44px;
  border-radius: var(--bazar-radius-pill);
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--bazar-muted);
  line-height: 1.45;
}

.final-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--bazar-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.final-word {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.06em;
  margin: 6px 0 10px;
  color: var(--bazar-black);
}

.final-score {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.best-line {
  font-size: 14px;
  color: var(--bazar-text-secondary);
  margin: 6px 0;
}

.result-meta {
  font-size: 12px;
  color: var(--bazar-muted);
  margin: 0 0 14px;
  line-height: 1.4;
}

/* Info sheet */
.overlay-info .overlay-card {
  text-align: left;
  max-width: 340px;
}

.info-word {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}

.info-category {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--bazar-radius-pill);
  background: var(--bazar-lime-soft);
  color: #3d5c00;
  margin-bottom: 12px;
}

.info-definition {
  font-size: 15px;
  line-height: 1.5;
  color: var(--bazar-text);
  margin: 0 0 16px;
}

/* Footer */
.footer-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px 12px;
  font-size: 12px;
  color: var(--bazar-muted);
  border-top: 0.5px solid var(--bazar-border);
}

.footer-bar .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--bazar-border-strong);
}

.footer-wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--bazar-black);
}

@media (min-width: 720px) {
  .app {
    max-width: 420px;
    margin: 16px auto;
    border-radius: var(--bazar-radius-lg);
    overflow: hidden;
    min-height: calc(100dvh - 32px);
    max-height: 920px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08);
  }

  .stage {
    min-height: 520px;
  }
}

@media (max-width: 360px) {
  .brand-sub {
    display: none;
  }

  .score-pill {
    padding: 5px 7px;
    min-width: 44px;
  }

  .kb-key {
    height: 40px;
    font-size: 12px;
  }
}

/* spacer so hints sit above keyboard without huge empty board */
.hint-bar {
  flex: 0 0 auto;
}
