:root {
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #161b22;
  --panel-2: #1b2230;
  --border: #242c38;
  --border-strong: #3b4656;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --green: #3a8f4d;
  --green-border: #52ad68;
  --yellow: #c9a227;
  --yellow-border: #e0b93f;
  --gray: #3a4350;
  --danger: #f06b6b;
  --key: #2b3644;
  --key-text: #e6edf3;
  --key-absent: #171d25;
  --key-absent-text: #8793a2;
  --shadow: 0 22px 70px rgba(0, 0, 0, .45);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-2: #f0f3f6;
  --border: #d8dee6;
  --border-strong: #b9c2cf;
  --text: #11161d;
  --muted: #5c6773;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --green: #4b9f5f;
  --green-border: #3c8a4f;
  --yellow: #d5ad35;
  --yellow-border: #c19a25;
  --gray: #8b98a8;
  --danger: #b83a3a;
  --key: #e9edf2;
  --key-text: #11161d;
  --key-absent: #c5cdd6;
  --key-absent-text: #5f6a76;
  --shadow: 0 22px 70px rgba(24, 39, 60, .18);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: clamp(20px, 4vw, 44px) clamp(14px, 4vw, 32px) 28px;
  background:
    radial-gradient(820px 420px at 50% -160px, color-mix(in srgb, var(--accent) 13%, transparent), transparent 72%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

button { color: inherit; }

.page {
  width: min(680px, 100%);
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(18px, 4vw, 30px);
}

.brand h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 32px);
  line-height: 1.1;
  letter-spacing: .09em;
}

.brand p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.button,
.icon-button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease, color .15s ease;
}

.button:hover,
.icon-button:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
}

.button:active { transform: translateY(1px); }

.button--primary {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
  background: var(--accent);
  color: var(--accent-text);
}

.button--primary:hover {
  background: color-mix(in srgb, var(--accent) 84%, #000);
  border-color: var(--accent);
}

.icon-button {
  width: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

.button:disabled,
.icon-button:disabled {
  opacity: .45;
  cursor: default;
  transform: none;
}

.game {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.board-wrap {
  position: relative;
  width: min(330px, 100%);
  margin: 0 auto;
}

.board {
  display: grid;
  gap: clamp(5px, 1.4vw, 8px);
  width: 100%;
}

/* Invisible field on top of the board: tapping the board focuses it, so the
   phone shows its own keyboard. The value is mirrored into the tiles. */
.type-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  -webkit-text-fill-color: transparent;
  font-size: 16px; /* iOS zooms the page for smaller fields */
  /* Nearly transparent, but not exactly 0: some engines then treat the field
     as hidden and skip it when hit-testing or scrolling it into view. */
  opacity: .01;
  cursor: text;
  -webkit-appearance: none;
  appearance: none;
}

.type-input:focus,
.type-input:focus-visible {
  outline: none;
  box-shadow: none;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1.4vw, 8px);
}

.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  color: var(--text);
  font-size: clamp(24px, 8vw, 34px);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

.tile--filled {
  border-color: var(--border-strong);
}

/* Only the cell that was just typed gets the pop animation. */
.tile--pop {
  animation: tile-pop .13s ease-out;
}

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

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

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

:root[data-theme="light"] .tile--absent { color: #fff; }

@keyframes tile-pop {
  from { transform: scale(.9); }
  to { transform: scale(1); }
}

.status {
  min-height: 1.5em;
  margin: 18px 0 14px;
  text-align: center;
  font-size: .93rem;
  font-weight: 650;
  color: var(--text);
}

.status--error { color: var(--danger); }
.status--warn { color: var(--yellow); }
.status--win { color: var(--green-border); }
.status--lose { color: var(--yellow); }

.keyboard {
  display: grid;
  gap: clamp(5px, 1.4vw, 8px);
  width: 100%;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: clamp(3px, 1vw, 5px);
}

.key {
  flex: 1 1 0;
  min-width: 0;
  height: clamp(42px, 11vw, 50px);
  padding: 0 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--key);
  color: var(--key-text);
  font-size: clamp(.7rem, 2.8vw, .88rem);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .1s ease;
}

.key:not(.key--correct):not(.key--present):not(.key--absent) {
  border-color: var(--border-strong);
}

.key:hover { border-color: var(--border-strong); }
.key--absent:hover { border-color: var(--key-absent); }
.key:active { transform: translateY(1px); }

.key--wide {
  flex: 1.55 1 0;
  font-size: clamp(.6rem, 2.3vw, .72rem);
  text-transform: none;
}

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

.key--present {
  border-color: var(--yellow-border);
  background: var(--yellow);
  color: #171308;
}

.key--absent {
  border-color: var(--key-absent);
  background: var(--key-absent);
  color: var(--key-absent-text);
}

.keyboard--disabled .key {
  cursor: default;
  opacity: .82;
}

.keyboard--disabled .key:active { transform: none; }

.touch-hint {
  display: none;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.45;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .touch-hint { display: block; }
}

/* Status and the on-screen keypad live in one tray, so the game can scroll
   them into view above the phone keyboard (see app.js). Nothing changes
   size: the tray is only what the browser is asked to keep on screen. */
.tray {
  display: flex;
  flex-direction: column;
}

.result {
  margin: 22px 0 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  animation: result-in .16s ease-out;
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 14px;
}

.result-head > span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.result-word {
  font-size: 1.25rem;
  letter-spacing: .12em;
}

.result-definition {
  margin: 9px 0 0;
  font-size: .9rem;
  line-height: 1.55;
}

.result-definition > span:first-child { color: var(--muted); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
  margin-top: 34px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .76rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- dialog */

.modal {
  width: min(440px, calc(100vw - 24px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(3, 7, 12, .68);
  backdrop-filter: blur(3px);
}

.modal-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: .02em;
}

.modal-note {
  margin: 7px 0 17px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
}

.field {
  display: block;
  margin-top: 13px;
}

.field > span {
  display: block;
  margin-bottom: 5px;
  font-size: .78rem;
  font-weight: 650;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  resize: vertical;
}

.field input {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.field textarea {
  min-height: 74px;
  font-size: .9rem;
  line-height: 1.45;
}

.field input:disabled,
.field textarea:disabled {
  opacity: .7;
}

.field-hint {
  margin: 5px 0 0;
  min-height: 1.25em;
  color: var(--muted);
  font-size: .74rem;
}

.field-hint--warn { color: var(--yellow); }

.form-message {
  margin: 12px 0 0;
  min-height: 1.3em;
  font-size: .8rem;
  font-weight: 600;
}

.form-message--error { color: var(--danger); }
.form-message--success { color: var(--green-border); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .button { min-height: 36px; }

@media (max-width: 560px) {
  .header {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar { justify-content: flex-start; }

  .button { flex: 0 1 auto; }

  .tile { border-radius: 8px; }

  .footer { flex-direction: column; }
}

@media (max-width: 370px) {
  body { padding-left: 9px; padding-right: 9px; }

  .board,
  .board-row { gap: 4px; }

  .keyboard,
  .keyboard-row { gap: 3px; }

  .tile { border-width: 1px; }
}

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