/* ==========================================================================
   BTime - Rubik's Cube Speedcubing Timer Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme Palettes & CSS Variables
   -------------------------------------------------------------------------- */

/* Default Light Theme */
:root {
  --bg: #f3f4f6;
  --bg-2: #f3f4f6;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-soft: #f8fafc;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #475569;
  --accent: #1d4ed8;
  --accent-2: #2563eb;
  --warning: #d97706;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}

/* Night / Dark Mode */
body.dark-mode {
  --bg: #0b1020;
  --bg-2: #0b1020;
  --panel: rgba(15, 23, 42, 0.9);
  --panel-strong: rgba(15, 23, 42, 0.96);
  --panel-soft: rgba(30, 41, 59, 0.8);
  --border: rgba(148, 163, 184, 0.15);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #7dd3fc;
  --accent-2: #38bdf8;
  --warning: #fbbf24;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.52);
}

/* Bella Pink Palette */
body[data-palette="shell-pink"] {
  --bg: #fff1f4;
  --bg-2: #fff1f4;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-soft: #fff7f9;
  --border: rgba(136, 19, 55, 0.12);
  --text: #4a1828;
  --muted: #805466;
  --accent: #be185d;
  --accent-2: #db2777;
  --warning: #b45309;
  --danger: #be123c;
  --success: #15803d;
  --shadow: 0 24px 60px rgba(136, 19, 55, 0.12);
}

/* Vanilla Cream / Dessert Palette */
body[data-palette="dessert"] {
  --bg: #fff4df;
  --bg-2: #fff4df;
  --panel: rgba(255, 251, 241, 0.94);
  --panel-strong: rgba(255, 253, 247, 0.98);
  --panel-soft: #fff8e9;
  --border: rgba(146, 85, 48, 0.16);
  --text: #4c3028;
  --muted: #80645a;
  --accent: #b45335;
  --accent-2: #d97745;
  --warning: #a16207;
  --danger: #bd3e48;
  --success: #4f7b4e;
  --shadow: 0 24px 60px rgba(120, 72, 36, 0.13);
}

/* Lavender / Purple Palette */
body[data-palette="purple"] {
  --bg: #f4f0ff;
  --bg-2: #f4f0ff;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-soft: #faf8ff;
  --border: rgba(76, 29, 149, 0.12);
  --text: #24133f;
  --muted: #62527e;
  --accent: #7c3aed;
  --accent-2: #6d28d9;
  --warning: #b45309;
  --danger: #c2415b;
  --success: #15803d;
  --shadow: 0 24px 60px rgba(76, 29, 149, 0.12);
}

/* Chessboard Monochromatic Palette */
body[data-palette="chessboard"] {
  --bg: #000000;
  --bg-2: #000000;
  --panel: #080808;
  --panel-strong: #080808;
  --panel-soft: #161616;
  --border: rgba(255, 255, 255, 0.36);
  --text: #ffffff;
  --muted: #ffffff;
  --accent: #000000;
  --accent-2: #333333;
  --warning: #ffffff;
  --danger: #ffffff;
  --success: #ffffff;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

/* Halloween Palette */
body[data-palette="halloween"],
body[data-palette="Halloween"] {
  --bg: #0d0a14;
  --bg-2: #0d0a14;
  --panel: rgba(26, 17, 36, 0.88);
  --panel-strong: rgba(30, 20, 42, 0.96);
  --panel-soft: #271838;
  --border: rgba(249, 115, 22, 0.28);
  --text: #fff7ed;
  --muted: #c4b5fd;
  --accent: #f97316;
  --accent-2: #ea580c;
  --warning: #fbbf24;
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: 0 24px 60px rgba(10, 5, 18, 0.65);
}

body[data-palette="halloween"] .page-shell,
body[data-palette="Halloween"] .page-shell {
  background: var(--bg);
}

body[data-palette="halloween"] .timer-display.holding,
body[data-palette="halloween"] .timer-display.inspecting.space-held,
body[data-palette="halloween"] .timer-state.holding,
body[data-palette="Halloween"] .timer-display.holding,
body[data-palette="Halloween"] .timer-display.inspecting.space-held,
body[data-palette="Halloween"] .timer-state.holding {
  color: #fb923c;
}

/* Christmas Palette */
body[data-palette="christmas"] {
  --bg: #f2fff5;
  --bg-2: #f2fff5;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-strong: rgba(255, 255, 255, 0.99);
  --panel-soft: #f7fff9;
  --border: rgba(14, 113, 57, 0.25);
  --text: #123d27;
  --muted: #486b57;
  --accent: #087c3a;
  --accent-2: #ed1c35;
  --warning: #a45d16;
  --danger: #c4122f;
  --success: #0e7d3e;
}

body[data-palette="christmas"] .page-shell {
  background: var(--bg);
}

body[data-palette="christmas"] .scramble-panel,
body[data-palette="christmas"] .history-panel {
  border-top: 4px solid #c81732;
}

body[data-palette="christmas"] .timer-panel,
body[data-palette="christmas"] .stats-panel {
  border-top: 4px solid #087c3a;
}

body[data-palette="christmas"] .panel-label,
body[data-palette="christmas"] .history-header h2 {
  color: #b5122b;
}

body[data-palette="christmas"] .stat-row:nth-child(odd) strong {
  color: #b5122b;
}

body[data-palette="christmas"] .stat-row:nth-child(even) strong {
  color: #087c3a;
}

body[data-palette="christmas"] .scramble-refresh {
  color: #fff;
  border-color: #c81732;
  background: #c81732;
}

body[data-palette="christmas"] .menu-button {
  color: #fff;
  border-color: #087c3a;
  background: #087c3a;
}

body[data-palette="christmas"] .solve-actions .result-action:nth-child(odd):not(:disabled) {
  color: #fff;
  border-color: #c81732;
  background: #c81732;
}

body[data-palette="christmas"] .solve-actions .result-action:nth-child(even):not(:disabled) {
  color: #fff;
  border-color: #087c3a;
  background: #087c3a;
}

/* Oil Spill Animated Palette */
body[data-palette="oilspill"] {
  --bg: #101321;
  --bg-2: #101321;
  --panel: rgba(17, 23, 40, 0.78);
  --panel-strong: rgba(17, 23, 40, 0.94);
  --panel-soft: rgba(30, 37, 57, 0.82);
  --border: rgba(133, 245, 223, 0.2);
  --text: #effffb;
  --muted: #b1c9ca;
  --accent: #68f0d1;
  --accent-2: #7ad5ff;
  --warning: #ffcf73;
  --danger: #ff829e;
  --success: #8bf2a6;
  --shadow: 0 24px 60px rgba(2, 8, 24, 0.36);
}

body[data-palette="oilspill"] {
  background:
    radial-gradient(ellipse at 18% 22%, rgba(0, 224, 190, 0.55), transparent 42%),
    radial-gradient(ellipse at 82% 18%, rgba(65, 91, 255, 0.5), transparent 40%),
    radial-gradient(ellipse at 74% 82%, rgba(210, 53, 178, 0.44), transparent 44%),
    radial-gradient(ellipse at 24% 78%, rgba(242, 174, 61, 0.34), transparent 42%),
    linear-gradient(125deg, #101321, #142431 48%, #18162b);
  background-size: 170% 170%;
  animation: oilspill-drift 24s ease-in-out infinite alternate;
}

body[data-palette="oilspill"] .page-shell {
  background: transparent;
}

/* Sunrise Palette */
body[data-palette="sunrise"] {
  --bg: #311b3b;
  --bg-2: #f4a261;
  --panel: rgba(64, 38, 72, 0.78);
  --panel-strong: rgba(54, 32, 65, 0.95);
  --panel-soft: rgba(91, 51, 76, 0.78);
  --border: rgba(255, 218, 165, 0.25);
  --text: #fff7e9;
  --muted: #f1c9ae;
  --accent: #ffbf69;
  --accent-2: #ff8b63;
  --warning: #ffd166;
  --danger: #ff829e;
  --success: #9be7a5;
  --shadow: 0 24px 60px rgba(41, 19, 51, 0.38);
}

body[data-palette="sunrise"] {
  background:
    radial-gradient(ellipse at 50% 100%, rgba(255, 205, 117, 0.84), transparent 32%),
    radial-gradient(ellipse at 48% 88%, rgba(255, 126, 92, 0.72), transparent 48%),
    radial-gradient(ellipse at 12% 18%, rgba(130, 75, 148, 0.58), transparent 43%),
    linear-gradient(160deg, #312049 0%, #744365 43%, #d87568 74%, #f6b66b 100%);
}

body[data-palette="sunrise"] .page-shell {
  background: transparent;
}

/* Shibuya Cyberpunk Animated Palette */
body[data-palette="shibuya"] {
  --bg: #080a18;
  --bg-2: #14132d;
  --panel: rgba(12, 14, 32, 0.78);
  --panel-strong: rgba(10, 12, 28, 0.94);
  --panel-soft: rgba(25, 25, 52, 0.86);
  --border: rgba(119, 234, 255, 0.38);
  --text: #fff8ff;
  --muted: #e0cce8;
  --accent: #70f5ff;
  --accent-2: #ff58c8;
  --warning: #ffe27a;
  --danger: #ff739f;
  --success: #84ffd0;
  --shadow: 0 24px 60px rgba(2, 4, 18, 0.62), 0 0 32px rgba(255, 63, 193, 0.12);
}

body[data-palette="shibuya"] {
  background:
    radial-gradient(ellipse at 9% 24%, rgba(255, 35, 151, 0.7), transparent 31%),
    radial-gradient(ellipse at 91% 18%, rgba(39, 115, 255, 0.68), transparent 34%),
    radial-gradient(ellipse at 72% 86%, rgba(0, 230, 255, 0.54), transparent 35%),
    radial-gradient(ellipse at 34% 65%, rgba(255, 147, 45, 0.48), transparent 32%),
    radial-gradient(ellipse at 55% 8%, rgba(198, 56, 255, 0.4), transparent 36%),
    linear-gradient(155deg, #100b24 0%, #211333 48%, #081c2c 100%);
  background-size: 180% 180%;
  animation: shibuya-glow 18s ease-in-out infinite alternate;
}

body[data-palette="shibuya"]::before {
  position: fixed;
  z-index: 0;
  inset: -12%;
  content: "";
  pointer-events: none;
  opacity: 0.8;
  filter: blur(42px);
  background:
    radial-gradient(ellipse 18% 24% at 14% 30%, rgba(255, 40, 164, 0.9), transparent 72%),
    radial-gradient(ellipse 22% 30% at 82% 20%, rgba(50, 111, 255, 0.86), transparent 72%),
    radial-gradient(ellipse 20% 28% at 72% 78%, rgba(20, 237, 255, 0.78), transparent 72%),
    radial-gradient(ellipse 16% 22% at 35% 70%, rgba(255, 159, 54, 0.72), transparent 72%),
    radial-gradient(ellipse 18% 26% at 54% 12%, rgba(203, 60, 255, 0.72), transparent 72%);
  animation: shibuya-light-drift 20s ease-in-out infinite alternate;
}

body[data-palette="shibuya"] .page-shell {
  position: relative;
  z-index: 1;
  background: transparent;
}

body[data-palette="shibuya"] .panel {
  border-color: rgba(114, 229, 255, 0.42);
  box-shadow: var(--shadow), inset 0 0 24px rgba(99, 75, 255, 0.08);
  backdrop-filter: blur(14px);
}

body[data-palette="shibuya"] .panel-label,
body[data-palette="shibuya"] .stat-row strong {
  text-shadow: 0 0 12px rgba(112, 245, 255, 0.6);
}

body[data-palette="shibuya"] .scramble-refresh,
body[data-palette="shibuya"] .menu-button {
  box-shadow: 0 0 16px rgba(255, 67, 194, 0.24);
}

/* --------------------------------------------------------------------------
   2. Keyframe Animations
   -------------------------------------------------------------------------- */

@keyframes shibuya-glow {
  from { background-position: 0% 20%; }
  to { background-position: 100% 80%; }
}

@keyframes shibuya-light-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(0.96); }
  to { transform: translate3d(2%, 1%, 0) scale(1.04); }
}

@keyframes oilspill-drift {
  0% { background-position: 0% 20%; }
  50% { background-position: 100% 70%; }
  100% { background-position: 25% 100%; }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-palette="oilspill"],
  body[data-palette="shibuya"] {
    animation: none;
  }

  body[data-palette="shibuya"]::before {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   3. Base Document & Reset
   -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: "Inter", sans-serif;
  background: linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

/* Animation backgrounds handled directly on body for each palette */

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* --------------------------------------------------------------------------
   4. Layout Structure & Header
   -------------------------------------------------------------------------- */

.page-shell {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(14px, 2.2vw, 36px);
  padding-top: max(clamp(14px, 2.2vw, 36px), env(safe-area-inset-top));
  padding-bottom: max(clamp(14px, 2.2vw, 36px), env(safe-area-inset-bottom));
  padding-left: max(clamp(14px, 2.2vw, 36px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 2.2vw, 36px), env(safe-area-inset-right));
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: clamp(12px, 2vh, 22px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.4vw, 16px);
}

.brand-mark {
  display: block;
  width: clamp(52px, 5.5vw, 80px);
  height: clamp(62px, 6.5vw, 96px);
  object-fit: contain;
  object-position: center;
  transition: transform 0.45s ease;
  transform: rotate(-10deg);
}

.brand-mark:hover {
    transform: rotate(-29deg) translateX(20px) scale(1.5);

}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-actions .menu {
  flex: 0 0 140px;
}

/* --------------------------------------------------------------------------
   5. Settings Menu
   -------------------------------------------------------------------------- */

.menu {
  position: relative;
}

.menu-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.menu-icon {
  font-size: 1rem;
  line-height: 1;
}

.settings-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.settings-menu[hidden] {
  display: none;
}

.menu-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.settings-category + .settings-category {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.settings-category-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.setting-row + .setting-row {
  border-top: 1px solid var(--border);
}

.setting-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.palette-select {
  flex: 0 1 150px;
  min-width: 0;
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   6. Main Application Layout & Panels
   -------------------------------------------------------------------------- */

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 350px);
  gap: clamp(14px, 1.8vw, 20px);
  flex: 1 1 auto;
  min-height: 0;
}

.timer-workspace {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(12px, 1.8vh, 18px);
}

.panel {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: clamp(14px, 1.8vh, 20px) clamp(16px, 1.8vw, 20px);
}

/* Scramble Panel */
.scramble-panel {
  min-height: clamp(90px, 15vh, 150px);
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.panel-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.scramble-refresh {
  display: inline-grid;
  flex: 0 0 42px;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.scramble-refresh:hover {
  transform: rotate(45deg);
  border-color: rgba(148, 163, 184, 0.35);
}

.scramble-refresh:active {
  transform: rotate(90deg) scale(0.96);
}

.scramble-refresh svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.scramble-text {
  margin: 0;
  min-height: auto;
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(0.95rem, 1.4vw, 1.35rem);
  line-height: 1.65;
  letter-spacing: 0.04em;
  color: var(--text);
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   7. Timer Display & State Controls
   -------------------------------------------------------------------------- */

.timer-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  background: var(--panel-strong);
  user-select: none;
  touch-action: none;
  cursor: default;
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Safari */
  -khtml-user-select: none;     /* Konqueror HTML */
  -moz-user-select: none;      /* Old Firefox */
  -ms-user-select: none;       /* Internet Explorer/Edge */
  user-select: none;           /* Non-prefixed version, supported by modern browsers */
}

.timer-panel:focus {
  outline: none;
}

.timer-state {
  margin-bottom: 10px;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.timer-display {
  width: 3.2ch;
  max-width: 100%;
  padding: 0 0.12em;
  border: 1px solid transparent;
  border-radius: 10px;
  outline: none;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-size: clamp(3.2rem, 9.5vh, 6.8rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  margin-bottom: clamp(10px, 1.8vh, 18px);
  color: var(--text);
  text-align: center;
  cursor: inherit;
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Safari */
  -khtml-user-select: none;     /* Konqueror HTML */
  -moz-user-select: none;       /* Old versions of Firefox */
  -ms-user-select: none;        /* Internet Explorer/Edge */
  user-select: none;            /* Non-prefixed version, supported by modern browsers */
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

/* Manual Time Entry Mode */
.timer-panel.manual-entry-active .timer-display {
  border-color: var(--border);
  background: var(--panel-soft);
  margin-bottom: 6px;
  caret-color: var(--accent);
  cursor: text;
  user-select: text;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.timer-panel.manual-entry-active .timer-display:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.timer-display[aria-invalid="true"] {
  color: var(--danger);
}

/* Timer State Colors */
.timer-state.ready {
  color: var(--muted);
}

.timer-state.inspecting {
  color: var(--warning);
}

.timer-state.ready-to-solve,
.timer-state.readyToSolve,
.timer-state.holding {
  color: var(--accent);
}

.timer-state.solving {
  color: var(--danger);
}

/* Timer Display State Modifiers */
.timer-display.holding {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(37, 99, 235, 0.2);
}

.timer-display.inspecting {
  color: var(--warning);
}

.timer-display.inspecting.space-held {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(37, 99, 235, 0.2);
}

body[data-palette="chessboard"] .timer-display.holding,
body[data-palette="chessboard"] .timer-display.inspecting.space-held,
body[data-palette="chessboard"] .timer-state.holding {
  color: #22c55e;
  text-shadow: none;
}


/* Hold Duration Feedback (Red while holding <0.75s, Green when ready >=0.75s) */
.timer-state.holding.holding-wait {
  color: var(--danger) !important;
}

.timer-display.holding-wait {
  color: var(--danger) !important;
  text-shadow: 0 0 20px rgba(220, 38, 38, 0.35) !important;
}

.timer-state.holding.holding-ready {
  color: var(--success) !important;
  font-weight: 700;
}

.timer-display.holding-ready {
  color: var(--success) !important;
  text-shadow: 0 0 26px rgba(34, 197, 94, 0.45) !important;
}

.timer-display.flash {
  animation: pulse 0.35s ease-in-out;
}

/* --------------------------------------------------------------------------
   8. Buttons & Solve Actions
   -------------------------------------------------------------------------- */

/* Standard Buttons */
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.result-action {
  min-width: 120px;
  width: 100%;
  min-height: 46px;
  height: 46px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 0 16px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease, border-color 0.18s ease;
  font-weight: 600;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.18);
}

.secondary-button,
.ghost-button,
.result-action {
  background: var(--panel-soft);
  border-color: var(--border);
  color: var(--text);
}

.ghost-button {
  min-width: 140px;
}

.danger-button {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.18);
  color: var(--danger);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.result-action:hover {
  transform: translateY(-1px);
}

/* Solve Result Actions (DNF, +2, Revert, Delete) */
.solve-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 252px);
  margin-bottom: 10px;
}

.solve-actions .result-action,
.solve-detail-actions .result-action {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  padding: 6px;
  font-size: 0.78rem;
}

.solve-actions .result-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   9. Statistics Panel
   -------------------------------------------------------------------------- */

.stats-panel {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  grid-column: 1 / -1;
  gap: 12px;
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Safari */
  -khtml-user-select: none;     /* Konqueror HTML */
  -moz-user-select: none;      /* Old Firefox */
  -ms-user-select: none;       /* Internet Explorer/Edge */
  user-select: none;           /* Non-prefixed version, supported by modern browsers */
}

.stat-row {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

.stat-row span {
  color: var(--muted);
}

.stat-row strong {
  font-size: 1.1rem;
  font-family: "Inter", sans-serif;
}

/* --------------------------------------------------------------------------
   10. History Panel & Scramble Visualizer
   -------------------------------------------------------------------------- */

.history-panel {
  min-width: 0;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

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

.history-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.history-controls {
  display: flex;
  flex: 0 0 234px;
  align-items: center;
  gap: 8px;
  width: 234px;
}

.history-controls #eventSelect {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  min-height: 46px;
  height: 46px;
  border-radius: 7px;
}

.history-controls #clearHistory {
  flex: 0 0 76px;
  width: 76px;
  min-width: 0;
  min-height: 46px;
  height: 46px;
  border-radius: 7px;
}

.event-select {
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  text-align-last: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.solve-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
  scrollbar-gutter: stable;
}

.solve-item {
  min-width: 0;
}

.solve-empty {
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
}

.solve-record-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 7px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.solve-record-button:hover {
  background: var(--panel);
  border-color: rgba(148, 163, 184, 0.35);
}

.solve-record-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.solve-record-button .index {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
}

.solve-record-button .time {
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}

.solve-record-button .tag {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Scramble 2D/3D Display Component */
.scramble-visual-panel {
  flex: 0 0 auto;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.scramble-visual-panel h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

scramble-display {
  display: block;
  width: 100%;
  height: 190px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-soft);
}

.scramble-visual-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.scramble-visual-status:empty {
  display: none;
}

.scramble-visual-credit {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
}

.scramble-visual-credit a {
  color: inherit;
}

/* --------------------------------------------------------------------------
   11. Dialog Modals (Solve Details & Confirm Clear)
   -------------------------------------------------------------------------- */

.solve-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(80vh, 680px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.solve-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.dialog-close {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.solve-detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.solve-detail-row span {
  color: var(--muted);
}

.solve-detail-row strong {
  font-family: "JetBrains Mono", monospace;
  text-align: right;
  
}

.solve-detail-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 252px);
  margin: 12px auto 0;
}

.scramble-detail {
  margin-top: 16px;
}

.scramble-detail h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.scramble-detail p {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-soft);
  font-family: "JetBrains Mono", monospace;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.confirm-message {
  margin: 0 0 20px;
  color: var(--muted);
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.confirm-actions button {
  min-width: 0;
}

/* --------------------------------------------------------------------------
   12. Responsive Breakpoints
   -------------------------------------------------------------------------- */

@media (max-width: 840px) {
  .page-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    padding: 14px 12px;
  }

  .app-layout {
    grid-template-columns: 1fr;
    flex: 0 0 auto;
    min-height: 0;
    gap: 14px;
  }

  .timer-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 12px;
  }

  .topbar {
    margin-bottom: 12px;
    align-items: center;
  }

  .brand-block {
    gap: 10px;
    
  }

  .brand-mark {
    width: 48px;
    height: 58px;
    
  }


  .eyebrow {
    font-size: 0.68rem;
    margin-bottom: 0;
  }

  h1 {
    font-size: 1.5rem;
  }

  .topbar-actions .menu {
    flex: 0 0 auto;
  }

  .topbar-actions .menu-button {
    min-width: 50px;
    height: 42px;
    padding: 0 12px;
    font-size: 0.88rem;
  }

  .scramble-panel,
  .stats-panel {
    grid-column: auto;
  }

  .scramble-panel {
    min-height: auto;
    padding: 12px 14px;
    gap: 8px;
  }

  .scramble-text {
    min-height: auto;
    font-size: clamp(0.95rem, 3.8vw, 1.25rem);
    line-height: 1.55;
  }

  .timer-panel {
    min-height: clamp(260px, 44vh, 380px);
    padding: 20px 14px;
  }

  .timer-display {
    font-size: clamp(3.8rem, 15vw, 5.8rem);
    margin-bottom: 14px;

  }

  .solve-actions {
    width: min(100%, 280px);
    gap: 8px;
    margin-bottom: 4px;
  }

  .solve-actions .result-action {
    aspect-ratio: auto;
    min-height: 42px;
    height: 42px;
    font-size: 0.82rem;
  }

  .stats-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .stat-row {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 90px;
    padding: 8px 10px;
    gap: 4px;
  }

  .stat-row span {
    font-size: 0.72rem;
  }

  .stat-row strong {
    font-size: 1rem;
  }

  .history-panel {
    height: auto;
    max-height: none;
    padding: 14px;
  }

  .solve-list {
    max-height: 280px;
  }

  scramble-display {
    height: 160px;
  }
}

@media (max-width: 520px) {
  .page-shell {
    padding: 10px 10px 18px 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .topbar {
    flex-wrap: nowrap;
    align-items: center;
  }

  .brand-block {
    gap: 8px;
  }

  .brand-mark {
    width: 40px;
    height: 48px;
  }

  .eyebrow {
    font-size: 0.62rem;
  }

  h1 {
    font-size: 1.35rem;
  }

  .topbar-actions .menu {
    flex-basis: auto;
  }

  .topbar-actions .menu-button {
    height: 38px;
    font-size: 0.82rem;
  }

  .timer-panel {
    min-height: clamp(230px, 40vh, 330px);
    padding: 16px 12px;
  }

  .timer-display {
    font-size: clamp(3.4rem, 16vw, 4.8rem);
  }

  .stat-row {
    flex: 1 1 calc(50% - 6px);
    padding: 8px 10px;
  }

  .history-header {
    flex-wrap: nowrap;
    gap: 8px;
  }

  .history-controls {
    flex: 0 0 auto;
    width: auto;
    gap: 6px;
  }

  .history-controls #eventSelect {
    min-height: 40px;
    height: 40px;
    font-size: 0.82rem;
    padding: 0 6px;
  }

  .history-controls #clearHistory {
    flex: 0 0 58px;
    width: 58px;
    min-height: 40px;
    height: 40px;
    font-size: 0.82rem;
  }

  .solve-record-button {
    padding: 10px 12px;
  }

  scramble-display {
    height: 145px;
  }
}

/* Smartphone & Device Landscape Optimization (e.g. iPhone, Android on desk) */
@media (max-height: 540px) and (orientation: landscape) {
  .page-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    padding: 8px 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .topbar {
    margin-bottom: 6px;
  }

  .brand-mark {
    width: 32px;
    height: 38px;
  }

  h1 {
    font-size: 1.15rem;
  }

  .eyebrow {
    display: none;
  }

    .topbar-actions .menu-button {
    height: 34px;
    min-width: 72px;
    font-size: 0.8rem;
  }

  .app-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 1fr);
    gap: 10px;
  }

  .timer-workspace {
    gap: 8px;
    grid-template-rows: auto auto auto;
  }

  .scramble-panel {
    min-height: auto;
    padding: 6px 12px;
    gap: 4px;
  }

  .scramble-text {
    font-size: 0.88rem;
    line-height: 1.35;
  }

  .timer-panel {
    min-height: 180px;
    padding: 10px;
  }

  .timer-display {
    font-size: clamp(2.6rem, 18vh, 4rem);
    margin-bottom: 4px;
  }

  .timer-state {
    margin-bottom: 4px;
    font-size: 0.72rem;
  }

  .solve-actions {
    margin-bottom: 4px;
    gap: 6px;
  }

  .solve-actions .result-action {
    min-height: 34px;
    height: 34px;
    font-size: 0.75rem;
  }

  .stats-panel {
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .stat-row {
    padding: 4px 6px;
    gap: 2px;
  }

  .stat-row span {
    font-size: 0.65rem;
  }

  .stat-row strong {
    font-size: 0.85rem;
  }

  .history-panel {
    height: auto;
    max-height: 85vh;
    padding: 10px;
  }

  .solve-list {
    max-height: 160px;
  }

  scramble-display {
    height: 120px;
  }
}
