:root {
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --bg: #1e1e2e;
  --panel-bg: #2a2a3c;
  --accent: #e0a458;
  --accent-2: #4caf82;
  --danger: #d9534f;
  --text: #f2f2f2;
  --text-dim: #a9a9bc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 560px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  text-align: center;
  margin-bottom: 12px;
}

header h1 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  color: var(--text-dim);
  margin: 4px 0 0;
}

.panel {
  width: 100%;
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hidden { display: none !important; }

.mode-choice {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-btn {
  background: var(--accent);
  border: none;
  color: #1e1e2e;
  font-weight: bold;
  font-size: 1rem;
  padding: 14px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.mode-btn:hover { opacity: 0.9; }
.mode-btn:active { transform: scale(0.97); }

.mode-btn.secondary {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

.mode-icon { margin-right: 6px; }

.records {
  display: flex;
  gap: 24px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.hud-item {
  flex: 1;
  text-align: center;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 8px 4px;
}

.hud-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.target-coord {
  display: block;
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.score {
  display: block;
  font-size: 1.8rem;
  font-weight: bold;
}

.timer-bar-wrap {
  width: 100%;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent-2);
  transform-origin: left;
  transition: width linear, background-color 0.2s ease;
}

.timer-bar.warning { background: var(--danger); }

.board-wrap {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 4px solid #3a2a1a;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s ease;
}

.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }

.square.correct { background: var(--accent-2) !important; }
.square.wrong { background: var(--danger) !important; }

.piece {
  width: 82%;
  height: 82%;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.piece-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.35));
}

.piece-shape {
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.piece-white .piece-shape {
  fill: #fbfaf7;
  stroke: #2b2b2b;
}

.piece-black .piece-shape {
  fill: #2b2926;
  stroke: #000000;
}

.quit-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.congrats {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--accent-2);
}

.gameover-actions {
  display: flex;
  gap: 12px;
}

@media (max-width: 420px) {
  header h1 { font-size: 1.5rem; }
  .target-coord, .score { font-size: 1.3rem; }
}
