/*
  Sketch / Doodle Theme for Wheel & CS Case Randomizer
  Hand-drawn irregular borders, pencil sketch shadows, Dark/Light modes.
*/

:root {
  /* Light Mode (Craft Notebook Paper) */
  --bg: #F8F5EE;
  --bg-card: #FFFFFF;
  --bg-elevated: #F1ECE0;
  --text-main: #1D2129;
  --text-muted: #5A6270;
  --text-dim: #8C95A6;
  --sketch-border: #242933;
  --sketch-shadow: #242933;
  --grid-color: rgba(36, 41, 51, 0.05);
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-gold: #EAB308;
  --accent-danger: #EF4444;
  --accent-success: #10B981;
  --font-sketch: 'Patrick Hand', 'Comic Neue', cursive, sans-serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Geist Mono', Consolas, monospace;
}

[data-theme="dark"] {
  /* Dark Mode (Graphite Chalkboard Paper) */
  --bg: #13151A;
  --bg-card: #1C1F26;
  --bg-elevated: #262A34;
  --text-main: #F3F4F6;
  --text-muted: #9CA3AF;
  --text-dim: #6B7280;
  --sketch-border: #E5E7EB;
  --sketch-shadow: #0A0C0F;
  --grid-color: rgba(255, 255, 255, 0.04);
  --accent: #3B82F6;
  --accent-hover: #60A5FA;
  --accent-gold: #FACC15;
  --accent-danger: #F87171;
  --accent-success: #34D399;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--text-main);
  font-family: var(--font-sketch);
  font-size: 18px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
  background-image: 
    linear-gradient(to right, var(--grid-color) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px);
  background-size: 28px 28px;
  overflow-x: hidden;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Sketch Box / Card Utility */
.sketch-card {
  background: var(--bg-card);
  border: 2px solid var(--sketch-border);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  box-shadow: 4px 4px 0px var(--sketch-shadow);
  padding: 24px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.sketch-card-sm {
  background: var(--bg-card);
  border: 2px solid var(--sketch-border);
  border-radius: 180px 10px 170px 12px/12px 170px 10px 180px;
  box-shadow: 3px 3px 0px var(--sketch-shadow);
  padding: 12px 16px;
}

/* Header */
header {
  border-bottom: 2px dashed var(--sketch-border);
  background: var(--bg);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-doodle {
  width: 42px;
  height: 42px;
  border: 2px solid var(--sketch-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
  background: var(--bg-card);
  transform: rotate(-4deg);
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.brand-text p {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-sans);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons */
.btn-sketch {
  font-family: var(--font-sketch);
  font-size: 18px;
  font-weight: 700;
  padding: 8px 18px;
  border: 2px solid var(--sketch-border);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 3px 3px 0px var(--sketch-shadow);
  cursor: pointer;
  transition: all 0.12s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.btn-sketch:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0px var(--sketch-shadow);
}

.btn-sketch:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0px var(--sketch-shadow);
}

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-spin-main {
  font-size: 26px;
  padding: 14px 44px;
  background: #10B981;
  color: #FFFFFF;
  border-width: 3px;
  box-shadow: 5px 5px 0px var(--sketch-shadow);
  transform: rotate(-1deg);
  letter-spacing: 0.05em;
}

.btn-spin-main:hover {
  transform: rotate(-1deg) translate(-2px, -2px);
  box-shadow: 7px 7px 0px var(--sketch-shadow);
  background: #059669;
}

.btn-spin-main:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
}

.btn-danger {
  color: var(--accent-danger);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Theme Toggle & Flags */
.btn-icon-sketch {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.lang-switch {
  display: flex;
  border: 2px solid var(--sketch-border);
  border-radius: 120px 8px 110px 10px/10px 110px 8px 120px;
  overflow: hidden;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
}

.lang-btn {
  background: var(--bg-card);
  border: none;
  padding: 6px 12px;
  font-family: var(--font-sketch);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.lang-btn.active {
  background: var(--text-main);
  color: var(--bg);
}

.flag-icon {
  width: 18px;
  height: 12px;
  display: inline-block;
  vertical-align: middle;
}

/* Mode Switcher Tabs */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 28px 0;
}

.mode-tab {
  font-family: var(--font-sketch);
  font-size: 20px;
  font-weight: 700;
  padding: 10px 24px;
  border: 2px solid var(--sketch-border);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 3px 3px 0px var(--sketch-shadow);
  transition: all 0.15s;
}

.mode-tab.active {
  background: var(--text-main);
  color: var(--bg);
  transform: rotate(-1deg);
  box-shadow: 5px 5px 0px var(--accent-gold);
}

/* Main Grid Layout */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 32px;
  margin-bottom: 60px;
}

/* Left Column: Stage (Wheel / Case Reel) */
.stage-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.title-editable-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 14px;
  border: 2px dashed transparent;
  border-radius: 8px;
  transition: all 0.2s;
}

.title-editable-wrap:hover {
  border-color: var(--sketch-border);
  background: var(--bg-elevated);
}

.title-editable {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.02em;
}

.title-edit-icon {
  font-size: 16px;
  color: var(--text-muted);
}

/* Canvas Wheel Wrap */
.wheel-container {
  position: relative;
  width: 500px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-canvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 4px solid var(--sketch-border);
  box-shadow: 6px 6px 0px var(--sketch-shadow);
  background: var(--bg-card);
  display: block;
}

/* Wheel Top Pointer */
.wheel-pointer {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 36px solid var(--accent-danger);
  filter: drop-shadow(2px 3px 0px var(--sketch-shadow));
  z-index: 10;
  pointer-events: none;
  transition: transform 0.05s ease;
}

.wheel-pointer.bounce {
  transform: translateX(-50%) scale(1.18);
}

/* Center Image Hub */
.wheel-center-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid var(--sketch-border);
  box-shadow: 3px 3px 0px var(--sketch-shadow);
  background: var(--bg-card);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  cursor: pointer;
}

.wheel-center-hub img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wheel-center-hub .hub-icon {
  font-size: 32px;
}

/* CS Case Reel Container */
.case-container {
  display: none;
  width: 100%;
  max-width: 680px;
  background: var(--bg-card);
  border: 3px solid var(--sketch-border);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  box-shadow: 6px 6px 0px var(--sketch-shadow);
  padding: 30px 20px;
  position: relative;
  overflow: hidden;
}

.case-reel-viewport {
  width: 100%;
  height: 190px;
  overflow: hidden;
  position: relative;
  border: 2px dashed var(--sketch-border);
  border-radius: 12px;
  background: var(--bg-elevated);
}

.case-needle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  background: var(--accent-gold);
  transform: translateX(-50%);
  z-index: 15;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.7);
}

.case-needle::before,
.case-needle::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
}

.case-needle::before {
  top: 0;
  border-top: 14px solid var(--accent-gold);
}

.case-needle::after {
  bottom: 0;
  border-bottom: 14px solid var(--accent-gold);
}

.case-track {
  display: flex;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.case-card {
  width: 150px;
  height: 100%;
  flex-shrink: 0;
  border-right: 2px solid var(--sketch-border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  user-select: none;
}

.case-card-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
}

.case-card-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 8px;
}

.case-card-title {
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

/* Rarity colors */
.rarity-blue { border-color: #4B69FF !important; }
.rarity-purple { border-color: #8847FF !important; }
.rarity-pink { border-color: #D32CE6 !important; }
.rarity-red { border-color: #EB4B4B !important; }
.rarity-gold { border-color: #FFD700 !important; }

/* Stage Bottom Controls */
.stage-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.stage-options-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 16px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 2px solid var(--sketch-border);
  border-radius: 120px 8px 110px 10px/10px 110px 8px 120px;
  padding: 6px 14px;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
}

.control-item input[type="number"] {
  width: 60px;
  background: var(--bg-elevated);
  border: 1px solid var(--sketch-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text-main);
  text-align: center;
}

/* Elimination Banner */
.elimination-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 2px dashed var(--accent-danger);
  border-radius: 12px;
  padding: 8px 16px;
  width: 100%;
  max-width: 500px;
}

.elimination-banner.active {
  display: flex;
}

/* Right Column: Settings & Items List */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px dashed var(--sketch-border);
  padding-bottom: 12px;
}

.sidebar-title {
  font-size: 24px;
  font-weight: 700;
}

.weight-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.weight-tab {
  flex: 1;
  text-align: center;
  padding: 6px 10px;
  font-size: 15px;
  font-weight: 700;
  border: 2px solid var(--sketch-border);
  border-radius: 180px 10px 170px 12px/12px 170px 10px 180px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
}

.weight-tab.active {
  background: var(--text-main);
  color: var(--bg);
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-muted);
  margin-bottom: 12px;
}

.stats-bar strong {
  color: var(--text-main);
}

/* Items List Scrollable */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 6px;
}

.items-list::-webkit-scrollbar {
  width: 6px;
}

.items-list::-webkit-scrollbar-thumb {
  background: var(--sketch-border);
  border-radius: 3px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 2px solid var(--sketch-border);
  border-radius: 180px 10px 170px 12px/12px 170px 10px 180px;
  padding: 8px 12px;
  box-shadow: 2px 2px 0px var(--sketch-shadow);
  transition: all 0.15s ease;
}

.item-row.eliminated {
  opacity: 0.45;
  background: var(--bg-elevated);
  text-decoration: line-through;
}

.item-color-picker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--sketch-border);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.item-color-picker input[type="color"] {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 50px;
  height: 50px;
  cursor: pointer;
  opacity: 0;
}

.item-img-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--sketch-border);
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
}

.item-input {
  flex: 1;
  background: transparent;
  border: none;
  font-family: var(--font-sketch);
  font-size: 18px;
  color: var(--text-main);
  outline: none;
  min-width: 0;
}

.item-weight-input {
  width: 52px;
  background: var(--bg-elevated);
  border: 1px solid var(--sketch-border);
  border-radius: 4px;
  padding: 3px 6px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-main);
  text-align: center;
  outline: none;
}

.item-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.item-btn:hover {
  color: var(--accent-danger);
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.sidebar-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 3px solid var(--sketch-border);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  box-shadow: 8px 8px 0px var(--sketch-shadow);
  width: 100%;
  max-width: 480px;
  padding: 30px;
  position: relative;
  animation: modalPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
  text-align: center;
}

.modal-desc {
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 20px;
}

/* Winner Modal Specifics */
.winner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-elevated);
  border: 3px solid var(--sketch-border);
  border-radius: 16px;
  box-shadow: 4px 4px 0px var(--sketch-shadow);
  margin-bottom: 24px;
  position: relative;
}

.winner-card.is-rare {
  border-color: var(--accent-gold);
  box-shadow: 0 0 24px rgba(250, 204, 21, 0.4), 4px 4px 0px var(--sketch-shadow);
}

.winner-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 12px;
}

.winner-name {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  line-height: 1.2;
}

.winner-chance {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 6px;
}

.winner-actions {
  display: flex;
  gap: 12px;
}

.winner-actions button {
  flex: 1;
}

/* Color Presets Palette Modal / Flyout */
.color-palette-popover {
  position: absolute;
  background: var(--bg-card);
  border: 2px solid var(--sketch-border);
  border-radius: 12px;
  box-shadow: 4px 4px 0px var(--sketch-shadow);
  padding: 12px;
  display: none;
  z-index: 200;
  width: 220px;
}

.color-palette-popover.active {
  display: block;
}

.color-palette-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 700;
}

.color-swatch-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}

.color-swatch-row:hover {
  background: var(--bg-elevated);
}

.swatch-circle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--sketch-border);
}

/* Footer */
footer {
  border-top: 2px dashed var(--sketch-border);
  padding: 30px 0;
  background: var(--bg);
  font-size: 15px;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-links a {
  color: var(--text-main);
  text-decoration: none;
  margin-left: 18px;
  font-weight: 700;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* Elimination Royale & Counters */
.stage-pool-pill {
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px dashed var(--sketch-border);
  border-radius: 20px;
  padding: 4px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.last-standing-box {
  background: var(--bg-card);
  border: 3px solid var(--accent-gold);
  border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
  box-shadow: 0 0 30px rgba(250, 204, 21, 0.4), 6px 6px 0px var(--sketch-shadow);
  padding: 28px 24px;
  text-align: center;
  width: 100%;
  max-width: 500px;
  margin-top: 10px;
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.last-standing-trophy {
  font-size: 46px;
  margin-bottom: 8px;
}

.last-standing-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-gold);
}

.last-standing-desc {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.last-standing-name {
  font-size: 30px;
  font-weight: 800;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 2px dashed var(--accent-gold);
  border-radius: 12px;
  padding: 8px 16px;
  display: inline-block;
}

.btn-sketch-sm {
  font-size: 14px !important;
  padding: 4px 12px !important;
}

.item-btn-eliminate {
  background: transparent;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.item-btn-eliminate:hover {
  transform: scale(1.15);
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* Responsive */
@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  .wheel-container {
    width: 340px;
  }
  .sidebar {
    max-width: 100%;
  }
}
