* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #fff;
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  --cell: min(17vw, calc((100dvh - 340px) / 4), 76px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

h1 { letter-spacing: 3px; font-size: clamp(18px, 4.5dvh, 26px); }
h2 { font-size: 13px; color: #aaa; font-weight: 600; }

.hud { display: flex; gap: 10px; }
.stat {
  font-size: clamp(15px, 3dvh, 20px);
  font-weight: bold;
  background: #16213e;
  padding: 4px 14px;
  border-radius: 8px;
}
.stat.low { color: #e94560; }

#current-word {
  font-size: clamp(20px, 4dvh, 26px);
  font-weight: bold;
  letter-spacing: 4px;
  min-height: 1.4em;
  color: #e94560;
  text-transform: uppercase;
}

#grid {
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  gap: calc(var(--cell) * 0.1);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.42);
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, transform 0.15s;
}

.cell.selected {
  background: #e94560;
  border-color: #ff6b81;
  transform: scale(1.08);
  z-index: 1;
}

.cell:not(.selected):hover { border-color: #5372b8; }

.controls { display: flex; gap: 10px; }

button {
  background: #0f3460;
  color: #fff;
  border: 2px solid #5372b8;
  border-radius: 8px;
  padding: 7px 18px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
}
button:hover { background: #5372b8; }

#submit { background: #2e7d32; border-color: #4caf50; }
#submit:hover { background: #388e3c; }

#message {
  min-height: 20px;
  font-weight: bold;
  font-size: 15px;
  text-align: center;
}
#message.ok { color: #4caf50; }
#message.bad { color: #e94560; }

#found {
  width: 100%;
  max-width: 420px;
  height: 64px;
  overflow: hidden;
  text-align: center;
}

#found-list, #missed-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}
#found-list { max-height: 44px; overflow: hidden; margin-top: 4px; }

#found-list li, #missed-list li {
  background: #16213e;
  border: 1px solid #4caf50;
  color: #4caf50;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  text-transform: uppercase;
}
#missed-list li { border-color: #e94560; color: #e94560; }

#bar { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
#bar .board { font-size: 13px; color: #aaa; margin-right: 4px; white-space: nowrap; }
#bar b { letter-spacing: 2px; color: #e94560; }
#bar button { padding: 6px 10px; font-size: 15px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 25, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 10;
}
.overlay[hidden] { display: none; }

.card {
  background: #1a1a2e;
  border: 2px solid #0f3460;
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.card h3 { font-size: 20px; }
#result-text { font-weight: bold; color: #4caf50; font-size: 14px; }
#missed-list { max-height: 38dvh; overflow: hidden; }
.card .controls { flex-wrap: wrap; justify-content: center; }

#stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #aaa;
  font-size: 13px;
}
#stats .summary { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; }
#stats .summary b { color: #fff; }
#stats svg { width: 100%; max-width: 280px; background: #16213e; border-radius: 8px; }
#stats table { width: 100%; border-collapse: collapse; text-align: center; }
#stats th, #stats td { padding: 3px 6px; border-bottom: 1px solid #0f3460; }
#stats th { color: #aaa; font-weight: normal; }
#stats td { color: #fff; }
#stats button { padding: 5px 12px; font-size: 12px; }
