/* ===================================================================
   TETRIS #1 — DESIGN SYSTEM
   Philosophy: Arcade Porcelain
   =================================================================== */

:root {
  /* ---- Color: neutrals (porcelain shell) ---- */
  --canvas: #F4F3EE;
  --surface: #FFFFFF;
  --surface-2: #EAE8E1;
  --surface-3: #DCD9D0;
  --line: #DEDBD2;
  --line-soft: #EAE8E1;
  --line-strong: #C7C3B8;

  --text: #2B2A26;
  --text-muted: #6B6960;
  --text-faint: #9C988C;

  /* ---- Color: accent (slate-blue) ---- */
  --accent: #4B5B8C;
  --accent-hover: #3E4D79;
  --accent-ink: #2E3A5F;
  --accent-soft: #E4E8F3;

  /* ---- Color: semantic ---- */
  --ok: #3E8E5A;
  --ok-soft: #E3F2E8;
  --info-soft: #E4E8F3;
  --warn: #B8842E;
  --warn-soft: #F5ECDC;
  --crit: #B5473D;
  --crit-soft: #F6E6E4;

  /* ---- Color: tetromino pieces (reserved, saturated — NEVER used in chrome/avatars/decoration) ---- */
  --piece-i: #3FBAC2;
  --piece-o: #E8B339;
  --piece-t: #8B5FBF;
  --piece-s: #5FAE5A;
  --piece-z: #D1584A;
  --piece-j: #4B6FBF;
  --piece-l: #D98A3D;

  /* ---- Radius ---- */
  --radius-card: 10px;
  --radius-control: 8px;
  --radius-nav: 7px;
  --radius-pill: 9999px;
  --radius-cell: 3px;

  /* ---- Spacing ---- */
  --gutter: 30px;
  --card-pad: 18px;
  --cell-pad: 12px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* ---- Typography ---- */
  --font-heading: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;

  --text-page-title: 17px;
  --text-card-title: 13.5px;
  --text-cell: 13px;
  --text-label: 13px;
  --text-description: 12.5px;
  --text-caps: 10.5px;

  /* ---- Shadow ---- */
  --shadow-whisper: 0 1px 2px rgba(43, 42, 38, 0.06), 0 1px 1px rgba(43, 42, 38, 0.04);
  --shadow-card: 0 2px 8px rgba(43, 42, 38, 0.08);

  /* ---- Motion ---- */
  --motion-fast: 120ms ease-out;
  --motion-base: 150ms ease-out;

  /* ---- Focus ---- */
  --focus-ring: 0 0 0 3px rgba(75, 91, 140, 0.25);
}

/* ===================================================================
   RESET & BASE
   =================================================================== */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  margin: 0;
  color: var(--text);
}

button { font-family: inherit; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ===================================================================
   LAYOUT SHELL
   =================================================================== */

.app-shell {
  display: grid;
  grid-template-rows: 52px 1fr;
  min-height: 100vh;
  width: 1280px;
  margin: 0 auto;
  background: var(--canvas);
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.breadcrumb strong { color: var(--text); font-weight: 600; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: 13px;
  width: 260px;
}
.kbd-chip {
  font-family: var(--font-body);
  font-size: 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--surface);
  color: var(--text-muted);
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

/* Avatar uses ONLY neutral/accent tokens — tetromino hues are reserved
   exclusively for game pieces and must never appear in chrome/decoration. */
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  font-family: var(--font-heading);
}

/* ---- Body grid: rail + content ---- */
.body-grid {
  display: grid;
  grid-template-columns: 212px 1fr;
  min-height: 0;
}

/* ===================================================================
   LEFT RAIL — two distinct modes:
   1) Stat readouts (.rail-stats-card) — plain, non-interactive, no
      active state. Used on oyun.html for Skor/Seviye/Satır.
   2) Nav items (.rail-item + .active) — real navigable destinations
      only (Oyun / Skor Tablosu / Nasıl Oynanır), or rare destructive
      actions in the "Veri" group (Skorları Temizle).
   =================================================================== */

.rail {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: var(--space-lg) 0;
  display: flex;
  flex-direction: column;
}

.rail-group-label {
  font-size: var(--text-caps);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
  padding: 0 var(--space-md);
  margin-bottom: var(--space-sm);
}

/* ---- Nav-mode item: real navigable destinations only ---- */
.rail-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  margin: 0 10px 2px;
  padding: 0 10px;
  line-height: 32px;
  border-radius: var(--radius-nav);
  font-size: var(--text-label);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--motion-fast);
}
.rail-item:hover { background: var(--surface-2); }
.rail-item:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.rail-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

.rail-item .ico { width: 16px; text-align: center; font-size: 13px; flex-shrink: 0; }

.rail-divider {
  height: 1px;
  background: var(--line);
  margin: var(--space-md) 14px;
}

/* Reserved strictly for rare, destructive, exiled actions (e.g. clearing
   score history) — NEVER for frequent in-game controls like End Game. */
.rail-item.danger { color: var(--crit); }
.rail-item.danger .ico { color: var(--crit); }
.rail-item.danger:hover { background: var(--crit-soft); }

/* ---- Readout-mode card: plain stat display, explicitly NOT a nav item.
   No .active state exists for this component — it is data, not a
   selectable destination. ---- */
.rail-stats-card {
  margin: 0 10px var(--space-md);
  padding: 0 10px;
  min-height: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
}
.rail-stats-card .stat-label {
  font-size: var(--text-caps);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  line-height: 1.6;
  padding-top: 10px;
}
.rail-stats-card .stat-value {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--accent-ink);
  padding-bottom: 10px;
}
.rail-stats-card .meter { margin: 0 0 10px; }

/* ===================================================================
   CONTENT COLUMN
   =================================================================== */

.content {
  padding: var(--space-xl) var(--gutter);
  overflow-y: auto;
}

.page-title {
  font-size: var(--text-page-title);
  font-weight: 650;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: var(--text-description);
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

/* ===================================================================
   CARDS
   =================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--line);border-radius: var(--radius-card);
  box-shadow: var(--shadow-whisper);
  margin-bottom: var(--space-lg);
  overflow: hidden;
}

.card-header {
  padding: var(--card-pad);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.card-title {
  font-size: var(--text-card-title);
  font-weight: 600;
  font-family: var(--font-heading);
}

.card-body { padding: var(--card-pad); }

.card-footer {
  padding: 14px var(--card-pad);
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

/* ===================================================================
   BUTTONS
   =================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 16px;
  border-radius: var(--radius-control);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--motion-fast), border-color var(--motion-fast);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-secondary:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Reserved strictly for genuinely destructive/terminal actions */
.btn-outline-crit {
  background: transparent;
  color: var(--crit);
  border-color: var(--crit);
}
.btn-outline-crit:hover { background: var(--crit-soft); }

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

/* ===================================================================
   FORM / FIELD
   =================================================================== */

.field-row {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: 14px 0;
}
.field-row + .field-row { border-top: 1px solid var(--line-soft); }

.field-label { width: 160px; flex-shrink: 0; font-weight: 500; }
.field-hint { font-size: var(--text-description); color: var(--text-muted); margin-top: 2px; }

input[type="text"], select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  width: 100%;
}
input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px; height: 20px;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left var(--motion-base);
}
.toggle.on::after { left: 18px; }

/* ===================================================================
   STATUS / BADGES
   =================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-info { background: var(--info-soft); color: var(--accent-ink); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-crit { background: var(--crit-soft); color: var(--crit); }
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ===================================================================
   TABLE
   =================================================================== */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: var(--text-caps);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 10px var(--cell-pad);
  border-bottom: 1px solid var(--line);
}
td {
  padding: var(--cell-pad);
  font-size: var(--text-cell);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
tbody tr { transition: background var(--motion-fast); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

.rank-badge {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.rank-badge.gold { background: #F5E6C3; color: #8A6A1E; }
.rank-badge.silver { background: #E6E6E3; color: #67665F; }
.rank-badge.bronze { background: #EAD5C3; color: #8A5A30; }

/* ===================================================================
   GAME-SPECIFIC: BOARD / CANVAS
   =================================================================== */

.game-area {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: var(--space-lg);
  align-items: start;
}

.board-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-well {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  padding: 4px;
}

canvas#oyun-tahtasi {
  display: block;
  background: #FBFAF7;
  border-radius: 4px;
}

.board-footer-controls {
  display: flex;
  gap: 8px;
  margin-top: var(--space-md);
}

/* Mini preview grid (next/hold piece) */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(4, 20px);
  grid-template-rows: repeat(4, 20px);
  gap: 2px;
  margin: 0 auto;
  padding: var(--space-sm);
  background: var(--surface-2);
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
}
.mini-cell { width: 20px; height: 20px; border-radius: var(--radius-cell); background: transparent; }
.mini-cell.filled { }

/* Piece color utility classes — reserved exclusively for actual game
   pieces (board cells, previews, legend swatches). Never apply these
   to chrome, avatars, nav, or any non-piece decoration. */
.piece-i { background: var(--piece-i); }
.piece-o { background: var(--piece-o); }
.piece-t { background: var(--piece-t); }
.piece-s { background: var(--piece-s); }
.piece-z { background: var(--piece-z); }
.piece-j { background: var(--piece-j); }
.piece-l { background: var(--piece-l); }

/* Progress meter (level progress) */
.meter {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--line-soft);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
}

/* Keyboard key chip for controls screen */
.key-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 28px;
  padding: 0 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* Controls 3-col grid (how-to-play) */
.controls-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}
.control-col {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--space-md);
  background: var(--surface);
}
.control-col.current {
  border: 2px solid var(--accent);
  position: relative;
}
.control-col .current-badge {
  position: absolute;
  top: -10px; right: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
}
.control-row:first-of-type { border-top: none; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 32px;
  margin-bottom: var(--space-sm);
  color: var(--text-faint);
}
.empty-state .empty-title {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

/* ===================================================================
   GAME-OVER ACTION BAR — the ONLY place --crit is used as a dominant
   treatment, because Game Over is the actual terminal/destructive-
   adjacent state the design-system's "crit" semantics are meant for.
   =================================================================== */
.gameover-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--card-pad);
  background: var(--crit-soft);
  border-top: 2px solid var(--crit);
}
.gameover-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--crit);
  font-weight: 600;
}
.gameover-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--crit);
}

/* ===================================================================
   MID-GAME ACTION ROW — normal secondary controls (Pause / Restart /
   End Game). End Game is intentionally a plain secondary button, NOT
   a crit/danger treatment: it is a frequent, low-stakes action the
   player can trigger mid-session, unlike the exiled "danger zone"
   pattern reserved for rare destructive settings actions.
   =================================================================== */
.ingame-actions {
  display: flex;
  gap: 8px;
  margin-top: var(--space-md);
}

/* Visually hidden (a11y) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Focus visibility globally */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-control);
}