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

html, button {
  touch-action: manipulation;
}

body {
  background: #0d0d1a;
  color: #e0e0e0;
  font-family: system-ui, -apple-system, sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  padding: 12px 16px 16px;
}

#wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 400px;
  height: 100%;
  overflow: hidden;
}

/* ── No-JS fallback ─────────────────────────────────────────────────────── */
#noscript-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 24px;
  text-align: center;
  color: #c0c0d8;
}

.noscript-reload {
  display: inline-block;
  padding: 10px 28px;
  border: 1px solid #3050a0;
  border-radius: 8px;
  color: #6080cc;
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}

.noscript-reload:hover {
  background: #1a2a4a;
  color: #80a0ee;
}

/* ── Header (two rows) ───────────────────────────────────────────────────── */
#header {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 6px;
}

.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.header-bottom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #a080ff;
  white-space: nowrap;
}

#btn-help {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #3a3a60;
  background: transparent;
  color: #8080b0;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-help:hover {
  background: #1e1e38;
  color: #c0a0ff;
  border-color: #6050a0;
}

/* ── Mode toggle (Daily / Practice) ─────────────────────────────────────── */
#modeToggle {
  display: flex;
  border: 1px solid #2a2a50;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #0c0c20;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.55);
}

.mode-btn {
  padding: 5px 9px;
  border: none;
  background: transparent;
  color: #8080b0;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn + .mode-btn {
  border-left: 1px solid #3a3a60;
}

.mode-btn:hover:not(.active) {
  background: #1e1e38;
  color: #a0a0d0;
}

.mode-btn.active {
  background: linear-gradient(175deg, #4a35a0 0%, #2d2278 100%);
  color: #f0e0ff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ── Difficulty toggle ───────────────────────────────────────────────────── */
#difficultyToggle {
  display: flex;
  border: 1px solid #2a2a50;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  margin-left: auto;
  background: #0c0c20;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.55);
}

.diff-btn {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: #8080b0;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.diff-btn + .diff-btn {
  border-left: 1px solid #3a3a60;
}

.diff-btn:hover:not(.active) {
  background: #1e1e38;
  color: #a0a0d0;
}

.diff-btn.active {
  background: linear-gradient(175deg, #4a35a0 0%, #2d2278 100%);
  color: #f0e0ff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */
#canvas-container {
  width: 100%;
}

#gameCanvas {
  display: block;
  width: 100%;
  border-radius: 12px;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.55);
}

/* ── Controls (color picker + action row) ───────────────────────────────── */
#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#colorPicker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.color-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.color-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c);
  border: 3px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-family: monospace;
  font-size: 0.9rem;
}

.color-btn:hover:not(:disabled) {
  transform: scale(1.15);
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.color-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.color-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ── Action row (⌫ Clear Submit New Results — all on one line) ──────────── */
#actions {
  display: flex;
  gap: 5px;
  width: 100%;
}

/* Base action-btn used by both game controls and dialog buttons */
.action-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  background: #2a2a4a;
  color: #ccc;
  transition: background 0.15s, transform 0.1s;
}

.action-btn:hover:not(:disabled) {
  background: #38385e;
}

.action-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Override sizing for buttons inside the game action row */
#actions .action-btn {
  flex: 1;
  padding: 9px 4px;
  font-size: 0.82rem;
  min-width: 0;
  text-align: center;
}

/* Submit stays purple but inherits the flex sizing */
#btn-submit {
  background: #5c3dcc;
  color: #fff;
  font-weight: 600;
}

#btn-submit:hover:not(:disabled) {
  background: #6e50dd;
}

/* Nav buttons (New Game / Results) look distinct from game controls */
.nav-btn {
  background: transparent !important;
  font-weight: 400 !important;
}

#btn-new {
  color: #6080cc;
  border: 1px solid #3050a0;
}

#btn-new:hover:not(:disabled) {
  background: #1a2a4a !important;
  color: #80a0ee;
}

#btn-results {
  color: #a080ff;
  border: 1px solid #5a3a90;
}

#btn-results:hover:not(:disabled) {
  background: #1e1430 !important;
  color: #c0a0ff;
}

#btn-results.hidden {
  display: none;
}

/* ── End-of-game dialog ──────────────────────────────────────────────────── */
#endDialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#endDialog.hidden {
  display: none;
}

#endDialogInner {
  background: #1a1a2e;
  border: 1px solid #3a3a60;
  border-radius: 16px;
  padding: 28px 24px;
  width: min(320px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#endTitle {
  text-align: center;
  font-size: 1.4rem;
  color: #a080ff;
  margin: 0;
}

#endStats {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: #c0c0d8;
  padding: 7px 0;
  border-bottom: 1px solid #252540;
}

.stat-row:last-of-type {
  border-bottom: none;
}

.score-row {
  padding-top: 10px;
  margin-top: 4px;
  border-top: 1px solid #3a3a60;
  border-bottom: none !important;
}

.score-row strong {
  font-size: 1.3rem;
  color: #a080ff;
}

.dot-red    { color: #ff6666; }
.dot-white  { color: #d0d0d0; }
.diff-value { color: #c0a0ff; }

.secret-reveal {
  text-align: center;
  font-size: 0.85rem;
  color: #808090;
  padding-top: 4px;
}

.secret-peg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  vertical-align: middle;
  margin: 0 2px;
  font-size: 0.7rem;
  font-weight: bold;
  font-family: monospace;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.action-btn.primary {
  background: #5c3dcc;
  color: #fff;
  font-weight: 600;
}

.action-btn.primary:hover:not(:disabled) {
  background: #6e50dd;
}

.text-btn {
  background: none;
  border: none;
  color: #6070a0;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 0;
  text-align: center;
  transition: color 0.15s;
}

.text-btn:hover {
  color: #9090c0;
}

/* ── Instructions dialog ─────────────────────────────────────────────────── */
#instructionsDialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
}

#instructionsDialog.hidden {
  display: none;
}

#instructionsInner {
  background: #1a1a2e;
  border: 1px solid #3a3a60;
  border-radius: 16px;
  padding: 24px 20px;
  width: min(340px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

#instructionsInner h2 {
  text-align: center;
  font-size: 1.3rem;
  color: #a080ff;
  flex-shrink: 0;
}

#instructionsContent {
  overflow-y: auto;
  font-size: 0.88rem;
  line-height: 1.6;
  color: #c0c0d8;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

#instructionsScrollHint {
  flex-shrink: 0;
  text-align: center;
  font-size: 1.1rem;
  color: #6070a0;
  line-height: 1;
  padding: 2px 0;
  animation: scrollBob 1.2s ease-in-out infinite;
  transition: opacity 0.25s;
}

#instructionsScrollHint.hidden {
  opacity: 0;
  pointer-events: none;
  animation: none;
}

@keyframes scrollBob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(4px); }
}

#instructionsContent h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: #9090c8;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 2px;
}

#instructionsContent ul {
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.fb-r { color: #ff6666; }
.fb-w { color: #d8d8d8; }
.fb-b { color: #404060; }

#admin-badge {
  font-size: 0.6rem;
  font-weight: 700;
  color: #c8a020;
  border: 1px solid #c8a020;
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.1em;
}

.clear-data-row {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid #252540;
  text-align: center;
}

.danger-btn {
  background: none;
  border: 1px solid #5a2a2a;
  color: #906060;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.danger-btn:hover {
  background: #2a1010;
  color: #d08080;
  border-color: #8a3030;
}
