:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --muted: #787c7e;
  --line: #d3d6da;
  --tile-empty-border: #d3d6da;
  --tile-filled-border: #878a8c;
  --key: #d3d6da;
  --key-fg: #1a1a1b;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --accent: #1a1a1b;
  --accent-fg: #ffffff;
  --danger: #b23b3b;
  --tile: 58px;
  --gap: 5px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #e9e9e9;
    --muted: #8f9091;
    --line: #3a3a3c;
    --tile-empty-border: #3a3a3c;
    --tile-filled-border: #565758;
    --key: #818384;
    --key-fg: #ffffff;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --accent: #e9e9e9;
    --accent-fg: #121213;
    --danger: #e07a7a;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

/* --- Kopfzeile ----------------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 15px;
}

.score {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.score b {
  color: var(--fg);
  font-weight: 600;
}

.linkbutton {
  background: none;
  border: 0;
  padding: 4px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.linkbutton:hover {
  color: var(--fg);
}

/* --- Layout -------------------------------------------------------------- */

main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  min-height: 0;
}

#view-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

#stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 0;
}

/* --- Gegnerstreifen ------------------------------------------------------ */

.opponent {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  flex: none;
}

.opponent .who {
  white-space: nowrap;
}

.opponent .who b {
  color: var(--fg);
  font-weight: 600;
}

.mini-rows {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.mini-row {
  display: flex;
  gap: 2px;
}

.mini {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--tile-empty-border);
}

.mini.c {
  background: var(--correct);
}
.mini.p {
  background: var(--present);
}
.mini.a {
  background: var(--absent);
}

/* --- Spielfeld ----------------------------------------------------------- */

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: var(--gap);
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}

.row.shake {
  animation: shake 0.5s;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-empty-border);
  border-radius: 3px;
  font-size: calc(var(--tile) * 0.5);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  color: var(--fg);
}

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

.tile.c,
.tile.p,
.tile.a {
  border-color: transparent;
  color: #fff;
}

.tile.c {
  background: var(--correct);
}
.tile.p {
  background: var(--present);
}
.tile.a {
  background: var(--absent);
}

.tile.reveal {
  animation: reveal 0.28s ease-out both;
}

@keyframes reveal {
  from {
    transform: scaleY(0.4);
    opacity: 0.4;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-6px);
  }
  40%,
  60% {
    transform: translateX(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.reveal,
  .row.shake {
    animation: none;
  }
}

/* --- Tastatur ------------------------------------------------------------ */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding-bottom: 6px;
  flex: none;
}

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

.key {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-fg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.key.wide {
  flex: 1.5 1 auto;
  font-size: 11px;
}

.key.c {
  background: var(--correct);
  color: #fff;
}
.key.p {
  background: var(--present);
  color: #fff;
}
.key.a {
  background: var(--absent);
  color: #fff;
  opacity: 0.75;
}

.kb-row .spacer {
  flex: 0.5 1 auto;
}

/* --- Panels, Formulare, Text --------------------------------------------- */

.panel {
  width: 100%;
  max-width: 320px;
  margin: 48px auto 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input:not([type]) {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  font: inherit;
}

input:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

button.primary {
  margin-top: 10px;
  padding: 12px 16px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.primary:disabled {
  opacity: 0.45;
  cursor: default;
}

button.secondary {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin: 4px 0 0;
}

.message {
  min-height: 20px;
  margin: 4px 0 8px;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
  flex: none;
}

.message.bad {
  color: var(--danger);
}

/* --- Zwischenzustaende (Wort stellen, Ergebnis) --------------------------- */

.prompt {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.prompt h1 {
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 6px;
}

.prompt p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.wordfield {
  display: flex;
  gap: 8px;
}

.wordfield input {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  font-size: 20px;
  font-weight: 600;
}

.result h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}

.words {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 18px 0 22px;
  font-size: 14px;
  color: var(--muted);
}

.words b {
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.1em;
}

/* Im Ergebnis steht das eigene Spielfeld weiterhin unter dem Fazit. */
.result .board {
  margin: 0 auto 22px;
}

/* --- Historie ------------------------------------------------------------ */

details {
  width: 100%;
  border-top: 1px solid var(--line);
  padding: 10px 2px;
  flex: none;
}

summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.hist-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.hist-row:last-child {
  border-bottom: 0;
}

.hist-outcome {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--muted);
  flex: none;
}

.hist-outcome.win {
  background: var(--correct);
}
.hist-outcome.loss {
  background: var(--danger);
}

.hist-row .when {
  margin-left: auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* --- Kleine Bildschirme -------------------------------------------------- */

@media (max-height: 700px), (max-width: 380px) {
  :root {
    --tile: 48px;
  }
  .key {
    height: 46px;
  }
}

@media (max-height: 600px) {
  :root {
    --tile: 40px;
  }
  .key {
    height: 40px;
  }
}
