:root {
  color-scheme: light;
  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --text: #1c1d2b;
  --text-muted: #5c5e73;
  --border: #e3e4f0;
  --accent: #6d5efc;
  --accent-strong: #5a4bf0;
  --accent-contrast: #ffffff;
  --success: #1fa971;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --shadow-sm: 0 1px 2px rgba(28, 29, 43, 0.06), 0 1px 1px rgba(28, 29, 43, 0.04);
  --shadow-md: 0 8px 24px rgba(28, 29, 43, 0.10);
  --shadow-lg: 0 16px 40px rgba(28, 29, 43, 0.16);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14141d;
  --bg-elevated: #1d1e2b;
  --text: #f0f1fa;
  --text-muted: #a3a5bd;
  --border: #2c2d40;
  --accent: #8a7dff;
  --accent-strong: #a094ff;
  --accent-contrast: #14141d;
  --success: #35c98a;
  --danger: #ff6b6b;
  --danger-bg: #3a1f24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14141d;
    --bg-elevated: #1d1e2b;
    --text: #f0f1fa;
    --text-muted: #a3a5bd;
    --border: #2c2d40;
    --accent: #8a7dff;
    --accent-strong: #a094ff;
    --accent-contrast: #14141d;
    --success: #35c98a;
    --danger: #ff6b6b;
    --danger-bg: #3a1f24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
  }
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; }
button { font-family: inherit; }
code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  background: var(--border);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-size: 0.92em;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  border-radius: 0 0 10px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Üst bar ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-cube {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: conic-gradient(from 45deg, #6d5efc, #35c98a, #ffd500, #ff6a13, #c8102e, #0057b8, #6d5efc);
  box-shadow: var(--shadow-sm);
}
.brand-name { font-size: 1.02rem; }
.header-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.icon-btn:hover { background: var(--border); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn-lg { width: 60px; height: 60px; background: var(--accent); color: var(--accent-contrast); border: none; box-shadow: var(--shadow-md); }
.icon-btn-lg:hover { background: var(--accent-strong); }

/* ---------- Genel yerleşim ---------- */
.layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 14px 140px;
  max-width: 1280px;
  margin: 0 auto;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.panel-sizes { padding: 10px; }

.size-buttons { display: flex; gap: 8px; }
.size-btn {
  flex: 1;
  padding: 12px 8px;
  min-height: 44px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.size-btn.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); color: var(--accent-strong); }
.size-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.size-btn .badge {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-top: 2px;
}

.viewport-wrap {
  position: relative;
  width: 100%;
  height: min(60vh, 460px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, color-mix(in srgb, var(--accent) 10%, var(--bg-elevated)), var(--bg-elevated));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  touch-action: none;
}
#kup-canvas { width: 100%; height: 100%; display: block; }
.viewport-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--bg-elevated) 75%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}
.celebration-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* ---------- Yüz navigasyonu (boyama modu overlay'i) ---------- */
.face-nav {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
}
.face-nav-row { display: flex; align-items: center; gap: 4px; }
.face-nav-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  color: var(--text);
  backdrop-filter: blur(6px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, background 0.12s ease;
}
.face-nav-btn:hover { background: var(--bg-elevated); }
.face-nav-btn:active { transform: scale(0.92); }
.face-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.face-indicator-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}
.face-indicator-swatch.is-unknown {
  background: transparent !important;
  border: 1px dashed var(--text-muted);
}

.panels-column { display: flex; flex-direction: column; gap: 14px; }

.collapsible summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  cursor: pointer;
  font-weight: 700;
  user-select: none;
  min-height: 44px;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible .chevron { transition: transform 0.2s ease; color: var(--text-muted); }
.collapsible[open] .chevron { transform: rotate(180deg); }
.panel-body { padding: 0 18px 18px; display: flex; flex-direction: column; gap: 12px; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); border: 1.5px solid var(--border); }
.btn-accent { background: linear-gradient(135deg, var(--accent), #35c98a); color: #fff; font-size: 1.05rem; box-shadow: var(--shadow-md); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.field-label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }
.link-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent-strong);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 4px 0;
  cursor: pointer;
  min-height: 32px;
}
.text-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.text-input:focus { border-color: var(--accent); }
.hint-text { font-size: 0.82rem; color: var(--text-muted); margin: 0; }

.mode-toggle { display: flex; gap: 6px; background: var(--bg); border-radius: var(--radius-md); padding: 4px; border: 1px solid var(--border); }
.mode-btn {
  flex: 1;
  min-height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.mode-btn.is-active { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-sm); }

.validation-msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
}

.paint-area { display: flex; flex-direction: column; gap: 12px; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 0.82rem; }
.palette { display: flex; gap: 10px; flex-wrap: wrap; }
.palette-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.palette-swatch {
  width: 48px; height: 48px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.palette-swatch.is-selected { border-color: var(--text); transform: scale(1.06); }
.palette-swatch.is-full { box-shadow: 0 0 0 2px var(--success); }
.palette-swatch.is-over { box-shadow: 0 0 0 2px var(--danger); }
.palette-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.palette-count.is-full { color: var(--success); }
.palette-count.is-over { color: var(--danger); }

.net-2d {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}
.net-2d-mini { max-width: 220px; }
.net-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
  cursor: pointer;
  min-width: 0;
  padding: 0;
}
.net-cell:disabled { visibility: hidden; cursor: default; }
.net-cell:hover { filter: brightness(1.1); }
.net-cell.is-current-face { outline: 2px solid var(--accent); outline-offset: -2px; }

.mini-map-details summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
  min-height: 32px;
  display: flex;
  align-items: center;
}
.mini-map-details summary::-webkit-details-marker { display: none; }

.solution-summary { font-weight: 700; font-size: 1rem; }
.move-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
}
.move-list li {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.move-list li.is-active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.move-list li.is-done { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }

/* ---------- Alt oynatma çubuğu ---------- */
.playback-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0,0,0,0.08);
}
.playback-controls { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.speed-control { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--text-muted); margin-left: 6px; }
.speed-control input[type="range"] { width: 90px; accent-color: var(--accent); }
.playback-progress { text-align: center; font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ---------- İletişim kutuları / toast ---------- */
.app-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 32px);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.app-dialog::backdrop { background: rgba(10, 10, 20, 0.55); backdrop-filter: blur(2px); }
.app-dialog h2 { margin-top: 0; }
.onboarding-steps { display: flex; flex-direction: column; gap: 10px; padding-left: 20px; margin: 16px 0; }
.notation-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.9rem; }
.notation-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }

.toast-area {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 0.88rem;
  animation: toast-in 0.25s ease;
}
.toast.toast-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }
.toast.toast-success { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Masaüstü düzeni ---------- */
@media (min-width: 960px) {
  .layout {
    display: grid;
    grid-template-columns: 340px 1fr 360px;
    grid-template-areas:
      "sizes  viewport solution"
      "input  viewport solution";
    align-items: start;
    padding-bottom: 40px;
  }
  .panel-sizes { grid-area: sizes; }
  .viewport-wrap { grid-area: viewport; height: min(72vh, 640px); }
  .panels-column { display: contents; }
  #panel-durum { grid-area: input; }
  #panel-cozum { grid-area: solution; align-self: start; }
  .playback-bar { position: sticky; bottom: 20px; margin-top: 16px; border-radius: var(--radius-lg); border: 1px solid var(--border); max-width: 900px; margin-left: auto; margin-right: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
