/* ==========================================================================
   脳トレラボ (Brain Training Lab) - Main Stylesheet
   ========================================================================== */

:root {
  --bg: #EEF1EC;
  --grid-line: rgba(31, 41, 55, 0.07);
  --ink: #1F2937;
  --ink-soft: #5B6472;
  --panel: #FFFFFF;
  --panel-dark: #16233B;
  --accent: #FF5A36;
  --accent-dark: #D8441F;
  --success: #2F6F4E;
  --success-bg: #E4F0E8;
  --amber: #FFC94A;
  --led: #FF8A3D;
  --border-subtle: rgba(31, 41, 55, 0.09);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Zen Kaku Gothic New", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
  line-height: 1.6;
  min-height: 100vh;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* --------------------------------------------------------------------------
   Top Navigation Bar & Header Controls
   -------------------------------------------------------------------------- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
  border-bottom: 1px dashed rgba(31, 41, 55, 0.12);
}

.back-portal-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  transition: color 0.15s ease;
}

.back-portal-link:hover {
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: var(--panel);
  border: 1px solid var(--border-subtle);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.btn-icon:hover {
  background: #ffffff;
  border-color: var(--ink-soft);
  transform: translateY(-1px);
}

.btn-icon.active {
  background: var(--panel-dark);
  color: #fff;
  border-color: var(--panel-dark);
}

/* --------------------------------------------------------------------------
   Hero & Scoreboard
   -------------------------------------------------------------------------- */
header.hero {
  padding: 32px 0 24px;
}

.eyebrow-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  display: inline-block;
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--accent-dark);
  background: #FFE7DD;
  border: 1px solid var(--accent);
  padding: 3px 9px;
  border-radius: 3px;
  font-weight: 700;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  background: #16233B;
  color: #FFC94A;
  padding: 3px 10px;
  border-radius: 3px;
  border: 1px solid #FFC94A;
  letter-spacing: 0.05em;
}

h1 {
  font-size: clamp(28px, 5.5vw, 48px);
  font-weight: 900;
  margin: 12px 0 8px;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h1 span {
  color: var(--accent);
}

.lede {
  color: var(--ink-soft);
  font-size: 16px;
  max-width: 600px;
  margin: 0 0 28px;
}

/* Scoreboard */
.scoreboard {
  background: var(--panel-dark);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  box-shadow: 0 10px 30px rgba(22, 35, 59, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.scoreboard::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--amber), var(--success));
}

.stat {
  text-align: left;
  border-left: 2px solid rgba(255, 255, 255, 0.12);
  padding-left: 14px;
}

.stat:first-child {
  border-left: none;
  padding-left: 0;
}

.stat-label {
  font-size: 11px;
  letter-spacing: .08em;
  color: #9FB0C9;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
}

.stat-value {
  font-family: "DotGothic16", monospace;
  font-size: 26px;
  color: var(--led);
  text-shadow: 0 0 10px rgba(255, 138, 61, 0.55);
  letter-spacing: .03em;
  min-height: 38px;
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.stat-value small {
  font-size: 13px;
  color: #9FB0C9;
  text-shadow: none;
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-weight: 500;
}

@media (max-width: 720px) {
  .scoreboard {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat {
    border-left: none;
    padding-left: 0;
  }
  .stat:nth-child(even) {
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    padding-left: 14px;
  }
}

@media (max-width: 480px) {
  .scoreboard {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .stat:nth-child(even) {
    border-left: none;
    padding-left: 0;
  }
}

/* --------------------------------------------------------------------------
   Game Grid Section & Cards
   -------------------------------------------------------------------------- */
section.games {
  padding: 32px 0 20px;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 22px;
  font-weight: 900;
  margin: 0 0 2px;
}

.section-sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 640px) {
  .game-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 20px;
  position: relative;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  user-select: none;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.1);
  border-color: rgba(31, 41, 55, 0.2);
}

.card::before, .card::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: var(--card-color, var(--accent));
  border-style: solid;
  opacity: .75;
  transition: opacity 0.15s ease;
}

.card:hover::before, .card:hover::after {
  opacity: 1;
}

.card::before {
  top: 6px; left: 6px;
  border-width: 2px 0 0 2px;
}

.card::after {
  bottom: 6px; right: 6px;
  border-width: 0 2px 2px 0;
}

.card .tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--card-color, var(--accent));
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.03);
  padding: 2px 8px;
  border-radius: 3px;
  display: inline-block;
}

.card h3 {
  margin: 10px 0 6px;
  font-size: 19px;
  font-weight: 700;
}

.card p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.card.active {
  outline: 2px solid var(--card-color, var(--accent));
  background: #FFFFFF;
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

/* --------------------------------------------------------------------------
   Game Panels
   -------------------------------------------------------------------------- */
.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--border-subtle);
  border-top: 4px solid var(--card-color, var(--accent));
  border-radius: var(--radius-sm);
  padding: 28px;
  margin-top: 20px;
  box-shadow: 0 12px 32px rgba(31, 41, 55, 0.08);
  animation: panelSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes panelSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel.open {
  display: block;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel h3 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 900;
}

.panel .close-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--ink-soft);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.panel .close-btn:hover {
  background: #F3F4F6;
  color: var(--ink);
  border-color: var(--ink-soft);
}

.game-area {
  margin-top: 18px;
  min-height: 140px;
  background: #F9FAFB;
  border: 1px solid rgba(31, 41, 55, 0.06);
  border-radius: var(--radius-sm);
  padding: 20px;
  position: relative;
}

/* --------------------------------------------------------------------------
   Buttons & UI Inputs
   -------------------------------------------------------------------------- */
button.primary {
  background: var(--card-color, var(--accent));
  color: #ffffff;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.1s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  touch-action: manipulation;
}

button.primary:hover {
  filter: brightness(0.92);
  transform: translateY(-1px);
}

button.primary:active {
  transform: translateY(0);
}

button.ghost {
  background: none;
  border: 1px solid var(--ink-soft);
  color: var(--ink);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

button.ghost:hover {
  background: #ffffff;
  border-color: var(--ink);
}

.big-readout {
  font-family: "DotGothic16", monospace;
  font-size: clamp(36px, 8vw, 54px);
  color: var(--accent-dark);
  margin: 10px 0;
  letter-spacing: 0.02em;
}

.feedback {
  font-weight: 700;
  font-size: 16px;
  min-height: 26px;
  margin-top: 10px;
}

.feedback.good {
  color: var(--success);
}

.feedback.bad {
  color: var(--accent-dark);
}

input.answer {
  font-family: "DotGothic16", monospace;
  font-size: 24px;
  padding: 8px 14px;
  width: 140px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  outline: none;
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input.answer:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 90, 54, 0.2);
}

/* --------------------------------------------------------------------------
   Game 1: Calc Sprint
   -------------------------------------------------------------------------- */
.timer-bar-container {
  width: 100%;
  height: 6px;
  background: #E5E7EB;
  border-radius: 3px;
  margin-bottom: 16px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 100%;
  transition: width 0.2s linear;
}

.flash-correct {
  animation: flashGreen 0.25s ease;
}

.flash-wrong {
  animation: shakeRed 0.3s ease;
}

@keyframes flashGreen {
  0% { background-color: rgba(47, 111, 78, 0.2); }
  100% { background-color: #F9FAFB; }
}

@keyframes shakeRed {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* --------------------------------------------------------------------------
   Game 2: Sequence Memory
   -------------------------------------------------------------------------- */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 12px;
  margin: 16px auto 0;
  justify-content: center;
}

.memory-tile {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  background: #DCE3DD;
  border: 1px solid rgba(31, 41, 55, 0.12);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.memory-tile:active {
  transform: scale(0.95);
}

.memory-tile.lit {
  background: #2F6F4E;
  box-shadow: 0 0 16px rgba(47, 111, 78, 0.6);
  border-color: #2F6F4E;
}

.memory-tile.disabled {
  cursor: default;
}

/* --------------------------------------------------------------------------
   Game 3: Schulte Grid (数字さがし)
   -------------------------------------------------------------------------- */
.schulte-grid {
  display: grid;
  grid-template-columns: repeat(5, 58px);
  gap: 8px;
  margin: 16px auto 0;
  justify-content: center;
  touch-action: manipulation;
}

.schulte-cell {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "DotGothic16", monospace;
  font-size: 22px;
  font-weight: 700;
  background: #DCE3DD;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(31, 41, 55, 0.1);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.12s ease, transform 0.08s ease, color 0.12s ease;
}

.schulte-cell:hover:not(.done) {
  background: #CED6CF;
}

.schulte-cell:active:not(.done) {
  transform: scale(0.94);
}

.schulte-cell.done {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
  cursor: default;
  opacity: 0.85;
}

@media (max-width: 640px) {
  .schulte-grid {
    grid-template-columns: repeat(5, 48px);
    gap: 6px;
  }
  .schulte-cell {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }
  .memory-grid {
    grid-template-columns: repeat(3, 64px);
    gap: 10px;
  }
  .memory-tile {
    width: 64px;
    height: 64px;
  }
}

/* --------------------------------------------------------------------------
   Game 4: Reaction Time Test
   -------------------------------------------------------------------------- */
.reaction-box {
  width: 100%;
  max-width: 420px;
  height: 200px;
  margin: 14px auto 0;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
  background: #6B7280;
  transition: background 0.12s ease, transform 0.08s ease;
  user-select: none;
  touch-action: manipulation;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.15);
  padding: 16px;
  text-align: center;
}

.reaction-box:active {
  transform: scale(0.99);
}

.reaction-box.wait {
  background: #C24B33;
}

.reaction-box.go {
  background: var(--success);
  box-shadow: 0 0 20px rgba(47, 111, 78, 0.4);
}

.reaction-subtext {
  font-size: 13px;
  font-weight: 500;
  margin-top: 6px;
  opacity: 0.9;
}

/* --------------------------------------------------------------------------
   Game 5: Stroop Test
   -------------------------------------------------------------------------- */
.stroop-word {
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-weight: 900;
  font-size: clamp(48px, 10vw, 68px);
  margin: 16px 0;
  letter-spacing: .04em;
  text-align: center;
  user-select: none;
}

.stroop-choices {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.stroop-choice {
  border: 2px solid rgba(0,0,0,0.15);
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
  opacity: 0.92;
  transition: all 0.12s ease;
  touch-action: manipulation;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.stroop-choice:hover {
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}

.stroop-choice .kbd-hint {
  font-size: 10px;
  background: rgba(255,255,255,0.25);
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Records / History Modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal-backdrop.open {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 540px;
  width: 100%;
  padding: 28px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #F9FAFB;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.record-item-label {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.record-item-value {
  font-family: "DotGothic16", monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-subtle);
  padding-top: 16px;
}

.btn-danger {
  background: none;
  border: 1px solid #EF4444;
  color: #EF4444;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-danger:hover {
  background: #FEF2F2;
}

/* --------------------------------------------------------------------------
   Game 6: じゃんけん脳トレ (Janken Challenge)
   -------------------------------------------------------------------------- */
.janken-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.janken-opponent {
  font-size: clamp(64px, 12vw, 84px);
  line-height: 1;
  user-select: none;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.1));
}

.janken-instruction {
  font-size: 20px;
  font-weight: 900;
  padding: 6px 20px;
  border-radius: var(--radius-sm);
  color: #ffffff;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: inline-block;
}

.janken-instruction.win {
  background: #E63946;
}

.janken-instruction.lose {
  background: #1D3557;
}

.janken-instruction.draw {
  background: #2F6F4E;
}

.janken-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.janken-btn {
  background: #FFFFFF;
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-size: clamp(32px, 6vw, 42px);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
  user-select: none;
  touch-action: manipulation;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.janken-btn small {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.janken-btn:hover {
  transform: translateY(-2px);
  border-color: var(--card-color, #E63946);
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
}

.janken-btn:active {
  transform: translateY(0);
}

/* Confetti overlay canvas */
#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2000;
}

footer {
  padding: 40px 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
  border-top: 1px solid rgba(31, 41, 55, 0.08);
  margin-top: 40px;
}
