:root {
  --ink: #15213c;
  --ink-soft: #263554;
  --paper: #f7f9ff;
  --paper-blue: #e9efff;
  --line: #bdc7dc;
  --muted: #6d7890;
  --correct: #238567;
  --present: #e7a826;
  --absent: #647089;
  --coral: #f06f5e;
  --white: #fff;
  --shadow: 0 22px 70px rgba(6, 14, 35, .28);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 18%, rgba(86, 121, 204, .28), transparent 29rem),
    linear-gradient(145deg, #101a31 0%, #1a2b50 62%, #15213c 100%);
  font-family: "Segoe UI", Arial, sans-serif;
}

button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

button:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 3px;
}

.page-shell {
  width: min(100% - 32px, 760px);
  min-height: calc(100vh - 36px);
  margin: 18px auto;
  overflow: hidden;
  background: var(--paper);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.topbar {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; font-weight: 900; letter-spacing: .08em; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: 9px;
  color: var(--white);
  background: var(--coral);
  border-radius: 8px 8px 8px 2px;
  font-family: Georgia, serif;
  font-size: 21px;
  letter-spacing: 0;
  transform: rotate(-3deg);
}
.brand-name { font-size: 17px; }
.brand-bridge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 27px;
  margin-inline: 1px;
  color: var(--white);
  background: var(--coral);
  border-radius: 5px;
  letter-spacing: 0;
  transform: rotate(3deg);
}
.brand-personal { color: var(--coral); }
.top-actions { display: flex; gap: 8px; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}
.icon-button:hover { background: var(--paper-blue); }

.game { padding: 28px 48px 34px; }
.intro { max-width: 540px; margin: 0 auto 24px; }
.eyebrow,
.dialog-kicker {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
}
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 5vw, 45px);
  line-height: .98;
  letter-spacing: -.045em;
}
h1 em { color: var(--correct); font-weight: 400; }
.attempt-counter {
  display: flex;
  align-items: baseline;
  flex: 0 0 auto;
  padding-bottom: 3px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.attempt-counter span { font-family: Georgia, serif; font-size: 34px; font-weight: 700; }
.attempt-counter small { color: var(--muted); font-size: 13px; font-weight: 700; }

.play-area { position: relative; margin-bottom: 20px; }
.message {
  position: absolute;
  z-index: 5;
  top: -12px;
  left: 50%;
  min-height: 0;
  padding: 0;
  color: var(--white);
  background: var(--ink);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: .2s ease;
  white-space: nowrap;
}
.message.show { padding: 9px 16px; opacity: 1; transform: translate(-50%, 0); }

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
  width: min(100%, 360px);
  margin: 0 auto;
}
.board-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.tile {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--white);
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: inset 0 -3px 0 rgba(21, 33, 60, .05);
  transform-style: preserve-3d;
  cursor: default;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .14s ease, box-shadow .14s ease, transform .14s ease;
}
.board-row.current .tile { cursor: pointer; }
.board-row.current .tile:not(.active):hover { border-color: #8795b2; }
.tile.active {
  border-color: var(--coral);
  background: #fff1ef;
  box-shadow: inset 0 -5px 0 var(--coral), 0 0 0 3px rgba(240, 111, 94, .16);
  transform: translateY(-2px);
}
.tile.active:focus-visible {
  outline: 3px solid rgba(240, 111, 94, .42);
  outline-offset: 3px;
}
.tile.filled { border-color: var(--ink-soft); animation: pop .12s ease-out; }
.tile.filled.active { border-color: var(--coral); }
.tile.reveal { animation: flip .55s ease both; }
.tile.correct { color: var(--white); border-color: var(--correct); background: var(--correct); }
.tile.present { color: var(--ink); border-color: var(--present); background: var(--present); }
.tile.absent { color: var(--white); border-color: var(--absent); background: var(--absent); }
.board-row.shake { animation: shake .32s ease; }
.board-row.win { animation: win .7s ease .2s; }
.board-new-game {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 360px);
  min-height: 46px;
  margin: 14px auto 0;
  padding: 0 17px;
  border: 0;
  border-radius: 10px;
  color: var(--white);
  background: var(--ink);
  box-shadow: 0 3px 0 #080f21;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}
.board-new-game[hidden] { display: none; }
.board-new-game:hover { background: var(--ink-soft); }
.board-new-game:active { transform: translateY(2px); box-shadow: 0 1px 0 #080f21; }
.board-new-game span { color: var(--coral); font-size: 20px; }

.keyboard-wrap {
  max-width: 590px;
  margin: 0 auto;
  padding: 14px 16px 16px;
  background: var(--paper-blue);
  border: 1px solid #d7def0;
  border-radius: 16px;
}
.keyboard { display: flex; flex-direction: column; gap: 6px; }
.key-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1 1 0;
  min-width: 0;
  height: 45px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 2px 0 #c8d1e4;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .08s ease, background .2s ease;
}
.key:hover { background: #fff8f7; }
.key:active { transform: translateY(2px); box-shadow: none; }
.key.wide { flex: 1.55 1 0; font-size: 11px; }
.key.correct { color: var(--white); background: var(--correct); box-shadow: 0 2px 0 #12624a; }
.key.present { color: var(--ink); background: var(--present); box-shadow: 0 2px 0 #ba8011; }
.key.absent { color: var(--white); background: var(--absent); box-shadow: 0 2px 0 #48536b; }

.dialog {
  width: min(calc(100% - 32px), 480px);
  padding: 34px;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(8, 14, 30, .72); backdrop-filter: blur(5px); }
.dialog-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: var(--paper-blue);
  font-size: 22px;
  cursor: pointer;
}
.dialog h2 { margin: 0 0 14px; font: 700 32px/1.05 Georgia, serif; letter-spacing: -.025em; }
.dialog p { line-height: 1.55; }
.examples { display: grid; gap: 9px; margin: 22px 0; }
.example { display: flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 700; }
.mini-tile { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; font-weight: 900; }
.mini-tile.correct { color: white; background: var(--correct); }
.mini-tile.present { background: var(--present); }
.mini-tile.absent { color: white; background: var(--absent); }
.dialog-note { color: var(--muted); font-size: 13px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 22px 0; }
.stats-grid div { text-align: center; }
.stats-grid strong { display: block; font: 700 27px Georgia, serif; }
.stats-grid span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; }
.distribution { display: grid; gap: 5px; margin: 18px 0 24px; }
.dist-row { display: grid; grid-template-columns: 16px 1fr; align-items: center; gap: 7px; font-size: 11px; font-weight: 800; }
.dist-bar { min-width: 26px; padding: 4px 6px; color: white; background: var(--ink-soft); border-radius: 4px; text-align: right; transition: width .5s ease; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; }
.secondary-button { flex: 1; min-height: 46px; border-radius: 10px; font-weight: 800; cursor: pointer; }
.secondary-button { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.reset-button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.reset-button:hover { color: #b34439; background: #fff0ee; }
.reset-button.confirming { color: var(--white); background: #b34439; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes flip { 0% { transform: rotateX(0); } 48% { transform: rotateX(90deg); } 52% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes win { 30% { transform: translateY(-8px); } 55% { transform: translateY(0); } 75% { transform: translateY(-4px); } }

@media (max-width: 620px) {
  body { background: var(--paper); }
  .page-shell { width: 100%; min-height: 100dvh; margin: 0; border-radius: 0; box-shadow: none; }
  .topbar {
    height: calc(60px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
  }
  .brand-name { font-size: 14px; letter-spacing: .055em; }
  .brand-mark { width: 29px; height: 29px; margin-right: 7px; font-size: 19px; }
  .brand-bridge { width: 17px; height: 24px; }
  .game { padding: 18px 14px max(18px, env(safe-area-inset-bottom)); }
  .intro { margin-bottom: 16px; padding: 0 5px; }
  .title-row { align-items: center; }
  h1 { font-size: 30px; }
  .attempt-counter span { font-size: 29px; }
  .board { width: min(100%, 318px); gap: 5px; }
  .board-new-game { width: min(100%, 318px); min-height: 43px; margin-top: 11px; }
  .board-row { gap: 5px; }
  .tile { border-radius: 8px; }
  .play-area { margin-bottom: 14px; }
  .keyboard-wrap { padding: 11px 5px 12px; border-radius: 12px; }
  .key-row { gap: 3px; }
  .key { height: 43px; border-radius: 5px; font-size: 12px; }
  .key.wide { font-size: 9px; }
  .dialog { padding: 30px 22px 24px; }
}

@media (max-height: 760px) and (min-width: 621px) {
  .page-shell { margin-block: 8px; min-height: calc(100vh - 16px); }
  .game { padding-block: 18px 22px; }
  .intro { margin-bottom: 14px; }
  .board { width: 300px; gap: 5px; }
  .board-row { gap: 5px; }
  .play-area { margin-bottom: 12px; }
  .key { height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
