/* ================================================================
   CHAIN REACT – SimplyJavaScript Game
   Master JavaScript array & string methods through method-chaining puzzles.
   styles.css
   ================================================================ */

/* ── Reset & base ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0d0d0d;
  color: #f0f0f0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout wrapper ── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* ================================================================
   TOP BAR
   ================================================================ */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: rgba(13, 13, 20, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(250, 204, 21, 0.18);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
  z-index: 20;
  gap: 6px 12px;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand {
  font-size: 0.95rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  letter-spacing: -0.2px;
  white-space: nowrap;
  text-decoration: none;
  transition: opacity 0.15s;
}
.brand:hover { opacity: 0.75; }
.brand-accent { color: #facc15; }

/* Controls */
.game-controls { display: flex; gap: 6px; align-items: center; }

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.18s, box-shadow 0.18s;
}
.ctrl-btn:hover {
  background: rgba(250, 204, 21, 0.12);
  border-color: rgba(250, 204, 21, 0.4);
  color: #facc15;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(250, 204, 21, 0.15);
}
.ctrl-btn:active { transform: translateY(0); box-shadow: none; }
.ctrl-btn svg { width: 14px; height: 14px; fill: currentColor; pointer-events: none; }

/* Stats row */
.stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat-value {
  color: #facc15;
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 22px;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
  transition: color 0.3s;
}

.stat-value.timer-low  { color: #fb923c; animation: timer-pulse 1s ease-in-out infinite; }
.stat-value.timer-crit { color: #f87171; animation: timer-pulse 0.5s ease-in-out infinite; }

.stat-value.score-pop { animation: score-pop 0.4s cubic-bezier(0.34,1.56,0.64,1) both; }

/* ================================================================
   PROGRESS BAR
   ================================================================ */
#progress-bar-container {
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
  z-index: 10;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #facc15, #f97316);
  transition: width 0.5s ease;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.35);
}

/* ================================================================
   GAME CONTENT AREA
   ================================================================ */
#game-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  background: radial-gradient(ellipse at 50% 0%, #131320 0%, #0a0a0a 80%);
  -webkit-overflow-scrolling: touch;
}

/* ================================================================
   PUZZLE HEADER  (concept tag + title)
   ================================================================ */
#puzzle-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  animation: fadeSlideIn 0.3s ease-out;
}

#concept-tag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #facc15;
  background: rgba(250, 204, 21, 0.1);
  border: 1px solid rgba(250, 204, 21, 0.25);
  border-radius: 20px;
  padding: 3px 12px;
}

#puzzle-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

/* ================================================================
   TARGET BOX
   ================================================================ */
#target-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(250, 204, 21, 0.05);
  border: 1px solid rgba(250, 204, 21, 0.2);
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  flex-wrap: wrap;
  transition: background 0.35s, border-color 0.35s, box-shadow 0.35s;
  animation: fadeSlideIn 0.35s ease-out;
}

#target-box.is-matched {
  background: rgba(74, 222, 128, 0.08);
  border-color: rgba(74, 222, 128, 0.45);
  box-shadow: 0 0 18px rgba(74, 222, 128, 0.1);
  animation: match-pop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.target-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

#target-value {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.88rem;
  font-weight: 500;
  color: #facc15;
  word-break: break-all;
  line-height: 1.5;
}

#target-box.is-matched #target-value { color: #4ade80; }

#target-match-badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 700;
  color: #4ade80;
  display: none;
  white-space: nowrap;
}
#target-box.is-matched #target-match-badge { display: block; }

/* ================================================================
   CHAIN BOX  (the code-editor-style chain display)
   ================================================================ */
#chain-box {
  width: 100%;
  max-width: 680px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #2a2a3a;
  background: #1a1a2e;
  transition: border-color 0.35s, box-shadow 0.35s;
  animation: fadeSlideIn 0.4s ease-out;
}

#chain-box.is-matched {
  border-color: rgba(74, 222, 128, 0.4);
  box-shadow: 0 0 22px rgba(74, 222, 128, 0.12);
}

/* Window chrome (traffic-light dots) */
#chain-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: #16162a;
  border-bottom: 1px solid #2a2a3a;
  flex-shrink: 0;
}

.code-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.code-dot.red    { background: #ff5f57; }
.code-dot.yellow { background: #ffbd2e; }
.code-dot.green  { background: #28c840; }

.code-filename {
  font-size: 0.73rem;
  color: #555;
  margin-left: 6px;
  font-family: 'Fira Code', 'Consolas', monospace;
  user-select: none;
}

/* Chain body – code area */
#chain-body {
  padding: 12px 16px 14px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.83rem;
  line-height: 1.75;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
}

/* Start line: let result = <value>; */
#start-line { color: rgba(255,255,255,0.55); }
.kw-let    { color: #c792ea; }       /* purple  */
.kw-var    { color: #fff; }           /* white   */
.kw-eq     { color: #89ddff; }        /* cyan    */
.kw-semi   { color: rgba(255,255,255,0.3); }

/* Chain step */
.chain-step {
  display: flex;
  align-items: baseline;
  padding-left: 12px;
  gap: 0;
  opacity: 0;
  animation: step-in 0.22s ease-out forwards;
}

.ch-indent  { color: transparent; user-select: none; display: inline-block; width: 2ch; }
.ch-dot     { color: rgba(255,255,255,0.25); }
.ch-name    { color: #82aaff; }       /* blue   */
.ch-args    { color: #f78c6c; }       /* orange */
.ch-arrow   { color: rgba(255,255,255,0.22); margin: 0 10px; }
.ch-result  { }

/* Syntax colors for values */
.v-str  { color: #c3e88d; }          /* green   */
.v-num  { color: #c792ea; }          /* purple  */
.v-bool { color: #ff9800; }          /* amber   */
.v-arr  { color: rgba(255,255,255,0.75); }
.v-pun  { color: rgba(255,255,255,0.3); }
.v-more { color: rgba(255,255,255,0.25); font-style: italic; }
.v-undef{ color: #555; }

.chain-step.step-match .ch-result { color: #4ade80; }
.chain-step.step-match .ch-arrow  { color: rgba(74,222,128,0.4); }

/* Check mark on matched step */
.step-check {
  margin-left: 10px;
  color: #4ade80;
  font-style: normal;
}

/* Current value row */
#current-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.28);
  display: flex;
  align-items: baseline;
  gap: 0;
  white-space: nowrap;
}

#current-val {
  color: rgba(255,255,255,0.7);
  transition: color 0.2s;
}
#current-val.is-matched { color: #4ade80 !important; }

/* Temporary error flash row */
.chain-error {
  color: #f87171;
  font-size: 0.78rem;
  padding-left: 12px;
  opacity: 0;
  animation: step-in 0.2s ease-out forwards, fade-out 0.4s 1.6s ease-in forwards;
  pointer-events: none;
}

/* ================================================================
   ACTION ROW  (Undo / Reset)
   ================================================================ */
#action-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 680px;
}

.action-btn {
  flex: 1;
  padding: 9px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.15s;
  font-family: 'Inter', sans-serif;
}
.action-btn:hover:not(:disabled) {
  background: rgba(250, 204, 21, 0.1);
  border-color: rgba(250, 204, 21, 0.35);
  color: #facc15;
  transform: translateY(-1px);
}
.action-btn:active:not(:disabled) { transform: translateY(0); }
.action-btn:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

/* ================================================================
   METHOD CARDS  (clickable method tiles)
   ================================================================ */
#cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 680px;
}

.method-card {
  padding: 11px 13px;
  border: 1px solid #2a2a3a;
  border-radius: 10px;
  background: #16162a;
  cursor: pointer;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.79rem;
  color: rgba(255, 255, 255, 0.7);
  text-align: left;
  line-height: 1.45;
  word-break: break-all;
  white-space: normal;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.15s, box-shadow 0.18s;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.method-card:hover:not(.is-disabled) {
  background: rgba(130, 170, 255, 0.08);
  border-color: rgba(250, 204, 21, 0.45);
  color: #facc15;
  transform: translateY(-2px);
  box-shadow: 0 5px 16px rgba(250, 204, 21, 0.12);
}

.method-card:active:not(.is-disabled) {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

.method-card.is-disabled {
  opacity: 0.32;
  pointer-events: none;
  cursor: default;
}

/* Card ripple on click */
.method-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(250,204,21,0.18) 0%, transparent 70%);
  opacity: 0;
  border-radius: 10px;
  transition: opacity 0.25s;
  pointer-events: none;
}
.method-card:active:not(.is-disabled)::after { opacity: 1; }

/* Syntax classes inside method card labels */
.mc-dot  { color: rgba(255,255,255,0.22); }
.mc-name { color: #82aaff; }
.mc-args { color: #f78c6c; }

/* ================================================================
   FEEDBACK  (shown after solve / timeout)
   ================================================================ */
#feedback-section {
  width: 100%;
  max-width: 680px;
  border-radius: 10px;
  padding: 16px 18px 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(13,13,20,0.7);
  animation: fadeSlideIn 0.3s ease-out;
}
#feedback-section.hidden { display: none !important; }

#feedback-section.fb-success {
  background: rgba(74, 222, 128, 0.07);
  border-color: rgba(74, 222, 128, 0.3);
}

#feedback-section.fb-timeout {
  background: rgba(248, 113, 113, 0.07);
  border-color: rgba(248, 113, 113, 0.3);
}

.fb-header {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

.fb-icon { font-size: 1.15rem; }

#feedback-score-gained {
  font-size: 0.83rem;
  font-weight: 600;
  color: #facc15;
  margin-bottom: 8px;
}

#feedback-explanation {
  font-size: 0.86rem;
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.68);
  user-select: text;
  -webkit-user-select: text;
  font-family: 'Inter', sans-serif;
}

#feedback-explanation code {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.81rem;
  color: #e5c07b;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Next button */
#next-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  width: 100%;
  padding: 11px 0;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #f09a0f, #d97e00);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: 'Inter', sans-serif;
}
#next-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(240, 154, 15, 0.38);
}
#next-btn:active { transform: translateY(0); }

/* ================================================================
   GAME-OVER OVERLAY
   ================================================================ */
#gameover-screen {
  position: absolute;
  inset: 0;
  background: rgba(6, 6, 14, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.4s ease-out;
}
#gameover-screen.hidden { display: none !important; }

#gameover-content {
  text-align: center;
  max-width: 380px;
  width: 100%;
}

#go-grade {
  font-size: 3.8rem;
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(135deg, #facc15, #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  animation: grade-in 0.6s cubic-bezier(0.34,1.56,0.64,1) both 0.1s;
}

#go-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}

#go-score-val {
  font-size: 2.1rem;
  font-weight: 800;
  color: #facc15;
  margin-bottom: 4px;
}

#go-subtitle {
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 24px;
  line-height: 1.5;
}

.go-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.go-stat {
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
}

.go-stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 5px;
}

.go-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #facc15;
}

#play-again-btn {
  display: block;
  width: 100%;
  padding: 13px 0;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #f09a0f, #d97e00);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: 'Inter', sans-serif;
  margin-bottom: 12px;
}
#play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(240, 154, 15, 0.4);
}

#back-games-link {
  display: inline-block;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.45);
  text-decoration: none;
  transition: color 0.18s;
  font-family: 'Inter', sans-serif;
}
#back-games-link:hover { color: rgba(255, 255, 255, 0.8); }

/* ================================================================
   UTILITY
   ================================================================ */
.hidden { display: none !important; }

/* ================================================================
   ANIMATIONS
   ================================================================ */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes step-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes match-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.025); }
  100% { transform: scale(1); }
}

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

@keyframes grade-in {
  from { opacity: 0; transform: scale(0.4) rotate(-6deg); }
  to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes score-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); color: #4ade80; }
  100% { transform: scale(1); }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 520px) {
  #game-content { padding: 14px 12px 24px; gap: 11px; }
  #chain-body { font-size: 0.77rem; padding: 10px 12px 12px; }
  .method-card { font-size: 0.73rem; padding: 9px 10px; }
  #cards-grid { gap: 8px; }
  .stats { gap: 5px; }
  .stat-item { padding: 4px 8px; font-size: 0.68rem; }
}

@media (max-width: 360px) {
  #cards-grid { grid-template-columns: 1fr; }
  .method-card { font-size: 0.76rem; }
}
