:root {
  /* palette */
  --bg: #f6fbff;
  --card: #ffffff;
  --surface: #ffffff;
  --border: #dbe7ef;
  --text: #0b0f14;
  --muted: rgba(11, 15, 20, 0.58);

  /* tiles + keys */
  --tileBg: #ffffff;
  --keyBg: #ffffff;

  /* feedback colors */
  --green: #2f9e59;
  --yellow: #d6a500;
  --gray: #94a3b8;

  /* layout */
  --gap: clamp(4px, 1vw, 8px);
  --tile: clamp(26px, 7.4vw, 42px);
  --tileTall: calc(var(--tile) + clamp(4px, 1.2vw, 10px));

  /* keyboard sizing */
  --keyH: clamp(34px, 7vw, 44px);
  --keyMinW: clamp(24px, 6.6vw, 38px);
  --keyWideW: clamp(48px, 14vw, 84px);

  /* strokes */
  --stroke: #0b0f14;
  --strokeW: 2px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  overflow-x: hidden;
}

.wrap {
  max-width: 860px;
  margin: 28px auto;
  padding: 0 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.card {
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

/* ===== Header ===== */

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.brand h1 {
  margin: 0;
  letter-spacing: 0.6px;
}

.sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 650;
}

.btn:hover {
  background: rgba(11, 15, 20, 0.04);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Grid ===== */

.grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: var(--gap);
  justify-content: center;
  padding: 10px 0 6px;
  width: 100%;
}

.row {
  display: grid;
  grid-template-columns: repeat(10, var(--tile));
  gap: var(--gap);
  justify-content: center;
  max-width: 100%;
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;

  border-radius: 10px;
  border: var(--strokeW) solid var(--stroke);
  background: var(--tileBg);
  color: var(--text);

  font: 850 clamp(13px, 3.2vw, 18px) / 1 system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  text-transform: uppercase;
  user-select: none;

  box-shadow: 0 1px 0 rgba(11, 15, 20, 0.04);
}

/* bridge columns are taller + slightly stronger border */
.tile.bridge-tile {
  height: var(--tileTall);
  border-width: 3px;
}

/* active caret tile */
.tile.active {
  outline: 2px solid rgba(11, 15, 20, 0.25);
  outline-offset: 2px;
}

/* default “filled” border fade */
.tile.filled {
  border-color: rgba(232, 238, 246, 0.2);
}

/* evaluation colors */
.tile.green {
  background: var(--green);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.tile.yellow {
  background: var(--yellow);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.tile.gray {
  background: var(--gray);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

/* bridge tiles: fade less than normal tiles (wins due to later order) */
.tile.bridge-tile.filled {
  border-color: rgba(11, 15, 20, 0.35);
}

.tile.bridge-tile.green,
.tile.bridge-tile.yellow,
.tile.bridge-tile.gray {
  border-color: rgba(11, 15, 20, 0.28);
}

/* ===== Meta row ===== */

.meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.bridge {
  color: var(--text);
}

.bridge-label {
  font-weight: 600;
}

#bridgePreview {
  color: var(--text);
  font-weight: 800;
  letter-spacing: 1px;
}

.status {
  font-weight: 600;
}

/* ===== Keyboard ===== */

.keyboard {
  margin-top: 12px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  margin: 8px 0;
  flex-wrap: nowrap;
}

.key {
  height: var(--keyH);
  min-width: var(--keyMinW);
  padding: 0 8px;

  border-radius: 10px;
  border: var(--strokeW) solid var(--stroke);
  background: var(--keyBg);
  color: var(--text);

  cursor: pointer;
  font-weight: 750;
  text-transform: uppercase;

  display: grid;
  place-items: center;
  flex: 0 0 auto;

  box-shadow: 0 1px 0 rgba(11, 15, 20, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.key:hover {
  background: rgba(11, 15, 20, 0.03);
}

.key.wide {
  min-width: var(--keyWideW);
}

.key.green {
  background: var(--green);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.key.yellow {
  background: var(--yellow);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.key.gray {
  background: var(--gray);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

/* ===== Dialog ===== */

.dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(640px, calc(100vw - 24px));
  background: transparent;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dialog-inner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.dialog-inner h2 {
  margin: 0 0 8px;
}

.dialog-inner p,
.dialog-inner li {
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}

.small {
  font-size: 13px;
}

.pill {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: -2px;
}

.pill.green {
  background: var(--green);
}

.pill.yellow {
  background: var(--yellow);
}

.pill.gray {
  background: var(--gray);
}

/* ===== Fonts for informational text ===== */

.info-font {
  font-family: "EB Garamond", Garamond, Georgia, serif;
}

/* ===== Landing ===== */

.landing {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  z-index: 9999;
}

.landing.show {
  display: block;
}

.landing-inner {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(18px, 4vw, 44px);
}

.landing-center {
  text-align: center;
  margin-top: clamp(48px, 12vh, 120px);
}

.landing-title {
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.6px;
  font-size: clamp(60px, 10vw, 92px);
  line-height: 1.02;
  margin: 0 auto clamp(32px, 5.5vh, 64px) auto;
}

.landing-subtitle {
  color: var(--text);
  font-weight: 200;
  font-size: clamp(24px, 4.8vw, 38px);
  line-height: 1.18;
  max-width: 780px;
  margin: 0 auto clamp(52px, 8.8vh, 98px) auto;
}

.landing-play {
  appearance: none;
  border: none;
  border-radius: 14px;
  background: #0b0f14;
  color: #fff;

  width: min(160px, 66vw);
  padding: 16px 22px;
  margin: 0 auto clamp(24px, 4.8vh, 52px) auto;

  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.2px;
  cursor: pointer;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.landing-play:hover {
  opacity: 0.92;
}

.landing-footer {
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  gap: 12px;
}

.landing-meta-line {
  line-height: 1.2;
}

/* ===== Toast ===== */

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;

  background: rgba(11, 15, 20, 0.92);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: min(520px, calc(100vw - 20px));
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(2px);
}

.toast.ok {
  background: rgba(47, 158, 89, 0.92);
}

.toast.warn {
  background: rgba(214, 165, 0, 0.92);
  color: #0b0f14;
}

.toast.err {
  background: rgba(11, 15, 20, 0.92);
}

/* ===== Result stats strip ===== */

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.stat {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  background: #fff;
  text-align: center;
}

.stat-num {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.05;
}

.stat-lbl {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
}

/* subtle color accents (no neon) */
.stat-win {
  border-color: rgba(47, 158, 89, 0.35);
  background: rgba(47, 158, 89, 0.06);
}

.stat-streak {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.06);
}

.stat-best {
  border-color: rgba(214, 165, 0, 0.35);
  background: rgba(214, 165, 0, 0.06);
}

/* ===== Site footer ===== */

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-top: 18px;
  padding-bottom: env(safe-area-inset-bottom);
  letter-spacing: 0.2px;
}

/* ===== Responsive ===== */

@media (max-width: 420px) {
  .result-stats {
    gap: 8px;
  }

  .stat {
    padding: 9px 8px;
  }

  .stat-num {
    font-size: 18px;
  }

  .card {
    padding: 12px;
  }

  .wrap {
    padding: 0 10px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  :root {
    --gap: 5px;
    --tile: 30px;
    --tileTall: 38px;
    --keyH: 36px;
    --keyMinW: 24px;
    --keyWideW: 58px;
  }
}
