:root {
  --sky: #70c5ce;
  --ink: #2b2b2b;
  --accent: #ffcc33;
  --accent-dark: #d99e1e;
  --panel: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--sky);
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  background: var(--sky);
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: 100vh;
  aspect-ratio: 2 / 3;
  image-rendering: -webkit-optimize-contrast;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.25);
}

#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(36px, 7vh, 64px);
  font-weight: 900;
  color: white;
  text-shadow:
    -2px -2px 0 #000, 2px -2px 0 #000,
    -2px 2px 0 #000,  2px 2px 0 #000,
    0 4px 6px rgba(0,0,0,0.3);
  pointer-events: none;
  z-index: 5;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(0,0,0,0.25), rgba(0,0,0,0.45));
  backdrop-filter: blur(2px);
  z-index: 10;
  text-align: center;
  overflow-y: auto;
}

.hidden { display: none !important; }

.logo {
  width: clamp(180px, 50vw, 360px);
  height: auto;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.won {
  width: clamp(160px, 40vw, 280px);
  height: auto;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.btn-primary {
  background: var(--accent);
  color: var(--ink);
  border: 3px solid var(--accent-dark);
  border-radius: 12px;
  padding: 14px 28px;
  font-size: clamp(18px, 3vh, 24px);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark), 0 6px 16px rgba(0,0,0,0.3);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
  touch-action: manipulation;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--accent-dark), 0 3px 8px rgba(0,0,0,0.3);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border: 2px solid #999;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: clamp(16px, 2.6vh, 20px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #999, 0 4px 12px rgba(0,0,0,0.2);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
  touch-action: manipulation;
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #999, 0 2px 6px rgba(0,0,0,0.2);
}

.btn-row, .diff-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  flex: 1 1 auto;
  min-width: 130px;
  max-width: 200px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border: 3px solid #777;
  border-radius: 16px;
  padding: 16px 24px;
  font-size: clamp(20px, 3.4vh, 28px);
  font-weight: 900;
  letter-spacing: 3px;
  cursor: pointer;
  box-shadow: 0 4px 0 #777, 0 6px 16px rgba(0,0,0,0.25);
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.diff-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #777, 0 3px 8px rgba(0,0,0,0.25);
}

.diff-btn[data-diff="easy"]  { border-color: #3a8a3a; box-shadow: 0 4px 0 #3a8a3a, 0 6px 16px rgba(0,0,0,0.25); color: #1f5026; }
.diff-btn[data-diff="hard"]  { border-color: #b03030; box-shadow: 0 4px 0 #b03030, 0 6px 16px rgba(0,0,0,0.25); color: #6e1a1a; }
.diff-btn[data-diff="easy"].selected { background: #cdedcd; }
.diff-btn[data-diff="hard"].selected { background: #f5cccc; }

.hint {
  color: rgba(255,255,255,0.9);
  font-size: 14px;
  margin: 0;
}

.final {
  background: var(--panel);
  border-radius: 16px;
  padding: 12px 32px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.final-label {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #666;
}

.final-score {
  font-size: clamp(40px, 8vh, 72px);
  font-weight: 900;
  line-height: 1;
}

.name-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.name-input label {
  font-weight: 700;
}

#name-field {
  width: 220px;
  font-size: 28px;
  text-align: center;
  font-family: "Courier New", monospace;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 4px;
  border: 2px solid var(--accent-dark);
  border-radius: 8px;
  padding: 8px 12px;
  background: white;
}

.board-wrap {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 20px;
  min-width: clamp(240px, 60vw, 360px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.board-wrap h2 {
  margin: 0 0 8px;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.board {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: "Courier New", monospace;
  font-size: 16px;
}

.board li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(0,0,0,0.15);
}

.board li:last-child { border-bottom: none; }

.board .rank { width: 28px; text-align: right; color: #888; }
.board .name { flex: 1; text-align: left; font-weight: 800; letter-spacing: 2px; }
.board .score { font-weight: 800; min-width: 60px; text-align: right; }
.board .empty { color: #888; font-style: italic; text-align: center; }

.board .me { background: rgba(255, 204, 51, 0.5); border-radius: 4px; }

#toasts {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
  width: min(92vw, 520px);
}

.toast {
  font-weight: 800;
  font-size: clamp(16px, 2.8vh, 22px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: toast-pop 1.8s ease-out forwards;
}

.toast .plus {
  color: #d62828;
  margin-right: 6px;
  font-weight: 900;
}

@keyframes toast-pop {
  0%   { opacity: 0; transform: translateY(20px) scale(0.85); }
  15%  { opacity: 1; transform: translateY(0)    scale(1.05); }
  25%  { transform: translateY(0) scale(1); }
  75%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-12px) scale(0.95); }
}
