/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #eef2f7;
  color: #2d3748;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────── */
#app-header {
  background: #1a2744;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
#app-header h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.02em; }

#btn-back {
  display: inline-flex;
  align-items: center;
  padding: 5px 13px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 7px;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
  flex-shrink: 0;
}
#btn-back:hover { background: rgba(255,255,255,0.28); }

#timer-section { display: flex; align-items: center; gap: 8px; }
#timer-display {
  font-family: 'Courier New', monospace;
  font-size: 1.55rem;
  font-weight: 700;
  background: rgba(0,0,0,0.35);
  color: #fff;
  padding: 3px 12px;
  border-radius: 6px;
  min-width: 76px;
  text-align: center;
  letter-spacing: 0.05em;
}
.btn-timer {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  min-width: 70px;
  text-align: center;
}
.btn-timer:hover { background: rgba(255,255,255,0.28); }

/* ── Settings bar ──────────────────────────────────────────────────── */
#settings-bar {
  background: #fff;
  border-bottom: 2px solid #dde3ed;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  flex-shrink: 0;
}
.setting-group { display: flex; align-items: center; gap: 6px; }
.setting-group > label:first-child {
  font-size: 0.82rem;
  font-weight: 600;
  color: #4a5568;
  white-space: nowrap;
}
.setting-group select,
.setting-group input[type="number"] {
  padding: 5px 8px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.88rem;
  background: #f8fafc;
  color: #2d3748;
  outline-color: #4299e1;
}
.setting-group input[type="number"] { width: 64px; }

.btn-primary {
  margin-left: auto;
  background: #3182ce;
  color: #fff;
  border: none;
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: #2b6cb0; }
.btn-primary:active { transform: scale(0.97); }

/* ── Game area ─────────────────────────────────────────────────────── */
#game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 28px;
  align-items: center;
  justify-content: flex-start;
}

.area-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #718096;
  margin-bottom: 8px;
  text-align: center;
}

#pattern-section, #bank-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#pattern-row, #bank-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

/* ── Sequence boxes ────────────────────────────────────────────────── */
.seq-box {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid #e2e8f0;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  line-height: 1;
}
.seq-box-blank {
  background: #f1f5f9;
  border-style: dashed;
  color: #cbd5e0;
}
.seq-box-blank::before {
  content: '?';
  font-size: 1.6rem;
  font-weight: 700;
  color: #cbd5e0;
}
.seq-box-active {
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66,153,225,0.28), 0 3px 8px rgba(0,0,0,0.08);
  background: #ebf4fb;
}

/* ── Bank tiles ────────────────────────────────────────────────────── */
.bank-tile {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  background: #fff;
  border: 2px solid #e2e8f0;
  box-shadow: 0 3px 8px rgba(0,0,0,0.10);
  font-size: 2.8rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.bank-tile:hover  { border-color: #4299e1; box-shadow: 0 4px 12px rgba(66,153,225,0.28); }
.bank-tile:active { transform: scale(0.96); }

/* ── Shake (wrong answer) ──────────────────────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px) rotate(-2deg); }
  40%      { transform: translateX(8px)  rotate(2deg); }
  60%      { transform: translateX(-6px) rotate(-1deg); }
  80%      { transform: translateX(6px)  rotate(1deg); }
}
.shake { animation: shake 0.45s ease; }

/* ── Extra settings panel ──────────────────────────────────────────── */
.btn-extra {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  background: #f8fafc;
  color: #2d3748;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-extra:hover   { background: #edf2f7; }
.btn-extra.is-open { background: #e6f0fb; border-color: #4299e1; }

#extra-panel {
  background: #fafbfd;
  border-bottom: 2px solid #dde3ed;
  padding: 10px 20px;
  max-height: 40vh;
  overflow-y: auto;
}
.extra-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.extra-panel-title { font-weight: 700; color: #2d3748; font-size: 0.9rem; }
.btn-extra-close {
  border: none !important;
  background: transparent !important;
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}
.extra-panel-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 20px;
  align-items: center;
}
.extra-panel-body .checkbox-label { padding: 4px 0; }
.extra-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #4a5568;
  cursor: pointer;
  white-space: nowrap;
}
.checkbox-label input[type="checkbox"] { cursor: pointer; accent-color: #3182ce; }

/* Prompt button in settings bar */
.btn-prompt {
  background: #dd6b20;
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-prompt:hover { background: #c05621; }

/* ── Prompt effects on bank tiles ──────────────────────────────────── */
@keyframes sparkle-pulse {
  0%   { box-shadow: 0 0 6px 3px #ffd700, 0 0 14px 6px rgba(255,215,0,0.55), 0 0 24px 10px rgba(255,165,0,0.25); }
  50%  { box-shadow: 0 0 12px 6px #ffd700, 0 0 28px 12px rgba(255,215,0,0.65), 0 0 44px 20px rgba(255,140,0,0.35); }
  100% { box-shadow: 0 0 6px 3px #ffd700, 0 0 14px 6px rgba(255,215,0,0.55), 0 0 24px 10px rgba(255,165,0,0.25); }
}
.bank-tile.prompt-sparkle {
  animation: sparkle-pulse 1s ease-in-out infinite;
  border-color: #d69e2e !important;
}
.bank-tile.prompt-outline {
  border: 3px solid #38a169 !important;
  box-shadow: 0 0 0 3px rgba(56,161,105,0.38), 0 3px 8px rgba(0,0,0,0.1) !important;
  background: rgba(56,161,105,0.05);
}

/* ── Next / Retry overlay ──────────────────────────────────────────── */
#bank-section { position: relative; }

#trial-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 20;
}
.btn-watermark {
  padding: 11px 30px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.28);
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}
.btn-watermark:hover  { opacity: 0.93; transform: scale(1.04); }
.btn-watermark:active { transform: scale(0.97); }
.btn-watermark-next  { background: rgba(47,133,90,0.92);  color: #fff; }
.btn-watermark-retry { background: rgba(192,86,33,0.88);  color: #fff; }

/* ── Bottom bar ────────────────────────────────────────────────────── */
#bottom-bar {
  background: #fff;
  border-top: 2px solid #dde3ed;
  padding: 9px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.btn-print     { background: #4a5568; color: #fff; border: none; padding: 7px 18px; border-radius: 8px; font-size: 0.88rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-print:hover { background: #2d3748; }
.btn-clear-data { background: #c53030; color: #fff; border: none; padding: 7px 18px; border-radius: 8px; font-size: 0.88rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-clear-data:hover { background: #9b2c2c; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 34px;
  padding: 0;
}
.btn-icon svg { width: 20px; height: 20px; fill: currentColor; }

/* ── Print section ─────────────────────────────────────────────────── */
#print-section { display: none; }
@media print {
  body > *:not(#print-section) { display: none !important; }
  #print-section {
    display: block;
    padding: 18px 24px;
    font-family: Arial, sans-serif;
    font-size: 11pt;
    color: #000;
  }
  #print-section h2 { font-size: 15pt; margin-bottom: 4px; }
  #print-meta { font-size: 9pt; color: #444; margin-bottom: 14px; }
  #results-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
  #results-table th, #results-table td {
    border: 1px solid #666; padding: 5px 8px; text-align: left; vertical-align: top;
  }
  #results-table th { background: #e8e8e8; font-weight: bold; font-size: 9.5pt; }
  #results-table tr:nth-child(even) td { background: #f7f7f7; }
  #results-table tr.settings-changed td { background: #e8e8e8 !important; }
  #results-table td.outcome-error      { color: #c0392b; }
  #results-table td.outcome-prompted   { color: #b7791f; }
  #results-table td.outcome-correction { color: #6b46c1; }
  #results-table td.outcome-ok         { color: #27ae60; }
  #print-summary { font-size: 9.5pt; color: #333; border-top: 1px solid #bbb; padding-top: 8px; }
  #print-summary span { margin-right: 20px; }
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  #app-header { padding: 8px 12px; gap: 8px; }
  #app-header h1 { font-size: 1.05rem; }
  #timer-display { font-size: 1.25rem; min-width: 62px; padding: 2px 8px; }
  .btn-timer { padding: 4px 9px; font-size: 0.76rem; }
  #settings-bar { padding: 6px 12px; gap: 8px; }
  .setting-group > label:first-child { font-size: 0.78rem; }
  .setting-group select,
  .setting-group input[type="number"] { font-size: 0.82rem; padding: 4px 6px; }
  .seq-box  { width: 60px; height: 60px; font-size: 1.9rem; }
  .bank-tile { width: 72px; height: 72px; font-size: 2.1rem; }
  #game-area { padding: 16px 12px; gap: 18px; }
}
@media (max-width: 480px) {
  .seq-box   { width: 48px; height: 48px; font-size: 1.5rem; }
  .bank-tile { width: 60px; height: 60px; font-size: 1.7rem; }
}
