/* =========================================================
   USORDLE - stylesheet
   Palette: Old Glory navy, flag red, paper white, star gold
   ========================================================= */

:root {
  --navy-900: #081730;
  --navy-800: #0b1f3f;
  --navy-700: #12295a;
  --navy-600: #1c3a75;
  --navy-500: #2a4f98;
  --red: #bf0a30;
  --red-dark: #96081f;
  --paper: #f6f7fb;
  --paper-dim: #c9d1e6;
  --gold: #f5b83d;

  --tile-empty: transparent;
  --tile-border: #34508a;
  --tile-border-filled: #7f93c4;
  --tile-correct: #2f6fde;
  --tile-present: #f5b83d;
  --tile-absent: #4a5878;
  --text-on-present: #1a1405;

  --key-bg: #22407f;
  --radius: 10px;

  --font-display: "Oswald", "Arial Narrow", Impact, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy-900);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
}

body {
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.07) 0 1.5px, transparent 2px) 0 0 / 46px 46px,
    radial-gradient(circle at 62% 68%, rgba(255,255,255,.05) 0 1.5px, transparent 2px) 0 0 / 46px 46px,
    radial-gradient(ellipse at 50% -10%, var(--navy-600), var(--navy-800) 55%, var(--navy-900));
  background-attachment: fixed;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.hidden { display: none !important; }

#app {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.screen {
  width: 100%;
  max-width: 560px;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- Start screen ---------- */

#screen-start { justify-content: center; align-items: stretch; padding-top: 18px; }

.stripe-bar {
  height: 14px;
  border-radius: 7px;
  margin-bottom: 18px;
  background: repeating-linear-gradient(90deg, var(--red) 0 22px, var(--paper) 22px 44px);
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}

.logo {
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(48px, 15vw, 84px);
  letter-spacing: .06em;
  line-height: 1;
  text-shadow: 0 3px 0 var(--red-dark);
}
.logo span { color: var(--gold); }

.tagline {
  margin: 8px 0 20px;
  text-align: center;
  color: var(--paper-dim);
  font-size: 17px;
}

.panel {
  background: rgba(8, 23, 48, .72);
  border: 1px solid var(--navy-600);
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(6px);
}

.field { margin-bottom: 16px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: var(--paper-dim);
}
.field-note { margin: 6px 0 0; font-size: 14px; color: var(--paper-dim); min-height: 20px; }

.seg {
  display: flex;
  background: var(--navy-900);
  border: 1px solid var(--navy-600);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 6px;
  border-radius: 7px;
  font-weight: 600;
  color: var(--paper-dim);
  transition: background .15s, color .15s;
}
.seg button.active { background: var(--navy-500); color: #fff; }
.seg button:not(.active):hover { background: var(--navy-700); }

.btn {
  border: 0;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 700;
}
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 3px 0 var(--red-dark); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-secondary { background: var(--navy-500); color: #fff; }
.btn-ghost { background: transparent; color: var(--paper-dim); border: 1px solid var(--navy-600); }
.btn-ghost:hover { background: var(--navy-700); color: #fff; }
.btn-big {
  width: 100%;
  padding: 14px;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: .08em;
}
.start-links { display: flex; gap: 8px; margin-top: 12px; }
.start-links .btn { flex: 1; padding: 9px 4px; font-size: 14px; }

/* ---------- Game screen ---------- */

#screen-game { height: 100dvh; padding-top: max(8px, env(safe-area-inset-top)); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 3px solid transparent;
  border-image: repeating-linear-gradient(90deg, var(--red) 0 14px, var(--paper) 14px 28px) 1;
}
.title-block { flex: 1; text-align: center; min-width: 0; }
.game-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: .1em;
  line-height: 1.1;
}
.game-sub {
  font-size: 13px;
  color: var(--paper-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toolbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--navy-700); }
.icon-btn.off { opacity: .45; }

.hint-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 8px 0 2px;
}
.chip {
  background: var(--navy-700);
  border: 1px solid var(--navy-500);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 14px;
  max-width: 100%;
}
.chip b { color: var(--gold); }
.chip-letters { font-family: var(--font-display); letter-spacing: .18em; font-size: 16px; }

.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
}

.board {
  --cols: 5;
  --rows: 6;
  display: grid;
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 6px;
  width: min(100%, calc(var(--cols) * 66px), calc((100dvh - 330px) * var(--cols) / var(--rows)));
  min-width: 190px;
}
.row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 6px;
}
.tile {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid var(--tile-border);
  border-radius: 6px;
  background: var(--tile-empty);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 7vw, 34px);
  text-transform: uppercase;
  user-select: none;
  transition: transform .08s;
}
.tile.filled { border-color: var(--tile-border-filled); animation: pop .1s ease-out; }
.tile.correct, .tile.present, .tile.absent { border-color: transparent; color: #fff; }
.tile.correct { background: var(--tile-correct); }
.tile.present { background: var(--tile-present); color: var(--text-on-present); }
.tile.absent { background: var(--tile-absent); }
.tile.flip { animation: flip .55s ease-in-out; }
.tile.bounce { animation: bounce .7s ease-in-out; }
.row.shake { animation: shake .45s; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-16px); }
  60% { transform: translateY(4px); }
  80% { transform: translateY(-6px); }
  100% { transform: translateY(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* ---------- Keyboard ---------- */

.keyboard { padding-top: 4px; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.key {
  flex: 1;
  max-width: 44px;
  height: clamp(44px, 7.4dvh, 56px);
  border: 0;
  border-radius: 7px;
  background: var(--key-bg);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-transform: uppercase;
  transition: background .2s, transform .05s;
}
.key:active { transform: scale(.94); }
.key.wide { flex: 1.6; max-width: 70px; font-size: 12px; }
.key.enter { background: var(--red); }
.key.correct { background: var(--tile-correct); }
.key.present { background: var(--tile-present); color: var(--text-on-present); }
.key.absent { background: #2a3350; color: #7f8aa8; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--paper);
  color: var(--navy-900);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out;
}
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(3, 9, 22, .78);
  display: grid;
  place-items: center;
  padding: 14px;
}
.modal-card {
  position: relative;
  width: min(100%, 460px);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  background: var(--navy-800);
  border: 1px solid var(--navy-500);
  border-top: 8px solid var(--red);
  border-radius: 14px;
  padding: 20px 18px 18px;
  animation: modal-in .18s ease-out;
}
@keyframes modal-in { from { transform: translateY(14px); opacity: 0; } }
.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  color: var(--paper-dim);
}
.modal h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: .06em;
  text-align: center;
}
.modal h3 { margin: 16px 0 6px; font-size: 16px; color: var(--gold); }
.modal p { margin: 6px 0; }
.modal ul { padding-left: 20px; margin: 6px 0; }
.modal li { margin-bottom: 4px; }
.modal .btn-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.modal .btn-row .btn { flex: 1; min-width: 120px; }

.example-row { display: flex; gap: 4px; margin: 8px 0 4px; }
.example-row .tile { width: 40px; font-size: 22px; }

/* Result */
.answer-word {
  text-align: center;
  font-family: var(--font-display);
  font-size: 40px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
}
.answer-def { text-align: center; color: var(--paper-dim); font-style: italic; }
.countdown { text-align: center; margin-top: 12px; color: var(--paper-dim); }
.countdown b { color: #fff; font-family: var(--font-display); font-size: 24px; letter-spacing: .08em; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 8px 0 12px; }
.stat-num { font-family: var(--font-display); font-size: 30px; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--paper-dim); }
.dist-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.dist-label { width: 14px; text-align: right; font-weight: 700; }
.dist-bar {
  min-width: 22px;
  padding: 1px 8px;
  text-align: right;
  font-weight: 700;
  background: var(--tile-absent);
  border-radius: 3px;
}
.dist-bar.hl { background: var(--tile-correct); }
.stat-context { text-align: center; color: var(--paper-dim); font-size: 14px; margin: 0 0 4px; }

/* Hints modal */
.hint-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--navy-700);
  border-radius: var(--radius);
}
.hint-item div { flex: 1; }
.hint-item small { display: block; color: var(--paper-dim); }
.hint-item .btn { padding: 8px 12px; }
.token-line { text-align: center; color: var(--paper-dim); margin-bottom: 10px; }
.token-line b { color: var(--gold); }

/* Archive */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.cal-head .month { font-family: var(--font-display); font-size: 20px; letter-spacing: .06em; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--paper-dim); padding-bottom: 2px; }
.cal-day {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--navy-600);
  border-radius: 8px;
  background: var(--navy-700);
  font-weight: 700;
  display: grid;
  place-items: center;
}
.cal-day:disabled { opacity: .25; cursor: default; }
.cal-day.won { background: var(--tile-correct); border-color: transparent; }
.cal-day.lost { background: var(--red-dark); border-color: transparent; }
.cal-day.today { outline: 2px solid var(--gold); }
.cal-day.progress::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
}
.cal-empty { visibility: hidden; }
.legend { display: flex; gap: 12px; justify-content: center; font-size: 13px; color: var(--paper-dim); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Small / short screens ---------- */

@media (max-width: 380px) {
  .key { font-size: 13px; }
  .kb-row { gap: 4px; }
  .icon-btn { width: 34px; }
}
@media (max-height: 640px) {
  .game-sub { display: none; }
  .hint-strip { min-height: 0; padding-top: 4px; }
  .board { width: min(100%, calc(var(--cols) * 66px), calc((100dvh - 270px) * var(--cols) / var(--rows))); }
}
@media (min-width: 700px) {
  .key { max-width: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
