:root {
  --bg-main: #f8fafc;
  --bg-panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f172a;
  --primary-hover: #334155;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
}

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

html,
body {
  width: 100%;
  /* We avoid fixed heights that break on mobile keyboard */
  min-height: 100vh;
  min-height: 100dvh;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3,
.modal-font {
  font-family: "Outfit", sans-serif;
}

/* Floating Toggles (Desktop) */
.sidebar-toggle-btn {
  position: fixed;
  z-index: 30;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.sidebar-toggle-btn:hover {
  background: #f1f5f9;
}
.sidebar-toggle-btn svg {
  width: 22px;
  height: 22px;
}

.right-toggle {
  right: 24px;
}
.settings-pos {
  top: 24px;
}
.history-pos {
  top: 84px;
}
.fullscreen-pos {
  top: 24px;
  left: 24px;
}

/* Proximity reveal: tombol memudar transparan, muncul saat kursor mendekat.
   Hanya untuk perangkat dengan mouse presisi (bukan touch), agar mobile tetap normal. */
@media (hover: hover) and (pointer: fine) {
  .sidebar-toggle-btn {
    opacity: 0.12;
  }
  .sidebar-toggle-btn.btn-near,
  .sidebar-toggle-btn:hover,
  .sidebar-toggle-btn:focus-visible {
    opacity: 1;
  }
}

/* Main Layout */
.container {
  display: flex;
  flex: 1;
  width: 100%;
  position: relative;
  /* Use min-height so it expands, not fixed height */
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden; /* Hide overflow horizontally */
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  width: 100%;
}

/* Sidebars */
.sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 380px;
  background: var(--bg-panel);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 40;
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 25px -5px rgba(0, 0, 0, 0.02);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Let sidebar content scroll naturally */
  overflow-y: auto;
}

.right-sidebar.hidden {
  transform: translateX(100%);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* Sidebar Header & Components */
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  flex-shrink: 0; /* Don't shrink header */
}
.sidebar h1 {
  margin: 0;
  font-size: 1.6rem;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.close-sidebar {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-sidebar:hover {
  background: #f1f5f9;
  color: var(--text-main);
}
.close-sidebar svg {
  width: 20px;
  height: 20px;
}

.panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.panel h2 {
  font-size: 0.8rem;
  margin: 0 0 12px 0;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
input[type="text"] {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: -8px 0 12px 2px;
}

button {
  font-family: inherit;
}
button.primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.styled-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 380px;
  overflow-y: auto;
}
.styled-list li {
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 500;
}
.styled-list li button {
  background: transparent;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 4px;
}
.styled-list li button:hover:not(:disabled) {
  color: var(--danger);
}
.styled-list li button.edit-btn {
  color: #94a3b8;
  font-size: 1rem;
}
.styled-list li button.edit-btn:hover:not(:disabled) {
  color: var(--accent);
}

.styled-list li.editing {
  gap: 8px;
}
.styled-list li .edit-name-input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 0;
}

.history-list {
  max-height: none !important;
  height: 100%;
}
.history-list li {
  background: var(--bg-main);
  border-color: transparent;
}

/* Switches */
.toggle-switch {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
}
.toggle-switch input {
  display: none;
}
.slider {
  position: relative;
  width: 40px;
  height: 22px;
  background-color: #cbd5e1;
  border-radius: 20px;
  margin-right: 12px;
  transition: 0.3s;
  flex-shrink: 0;
}
.slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toggle-switch input:checked + .slider {
  background-color: var(--accent);
}
.toggle-switch input:checked + .slider:before {
  transform: translateX(18px);
}

/* Wheel Components */
.wheel-container {
  position: relative;
  width: 100%;
  max-width: 550px;
  margin: 0 auto;
  /* Aspect ratio fallback if needed */
  aspect-ratio: 1/1;
}
.wheel-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.08));
}

.pointer {
  position: absolute;
  top: 50%;
  right: -15px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-right: 25px solid var(--primary);
  filter: drop-shadow(-2px 0 5px rgba(0, 0, 0, 0.1));
  z-index: 10;
}

#spin-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22%;
  height: 22%;
  min-width: 70px;
  min-height: 70px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  border: 6px solid var(--bg-main);
  box-shadow:
    0 4px 15px rgba(0, 0, 0, 0.15),
    inset 0 4px 6px rgba(255, 255, 255, 0.2);
  font-size: clamp(1rem, 3vw, 1.3rem);
  font-family: "Outfit", sans-serif;
  font-weight: 800;
  cursor: pointer;
  z-index: 20;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
#spin-btn:hover:not(:disabled) {
  transform: translate(-50%, -50%) scale(1.05);
  box-shadow:
    0 8px 25px rgba(15, 23, 42, 0.3),
    inset 0 4px 6px rgba(255, 255, 255, 0.2);
  background: var(--primary-hover);
}
#spin-btn:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.95);
}
#spin-btn:disabled {
  background: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

/* Modals */
#modal-overlay,
#confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
#modal-overlay.active,
#confirm-modal.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-panel);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  transform: scale(0.95) translateY(10px);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  max-width: 90%;
  width: 450px;
  border: 1px solid var(--border);
}
#modal-overlay.active .modal,
#confirm-modal.active .modal {
  transform: scale(1) translateY(0);
}

.modal h2 {
  font-size: 2.5rem;
  margin: 0 0 8px;
  color: var(--primary);
}
.modal p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 1.05rem;
}

#winner-name {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  margin: 0 0 32px;
  color: var(--accent);
  line-height: 1.2;
  word-wrap: break-word;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.modal-buttons button {
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
button.btn-close {
  background: #f1f5f9;
  color: var(--text-main);
}
button.btn-close:hover {
  background: #e2e8f0;
}
button.btn-again {
  background: var(--accent);
  color: white;
}
button.btn-again:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* MOBILE RESPONSIVENESS */
@media (max-width: 768px) {
  /* Adjust container to handle overflow gracefully on mobile */
  .container {
    flex-direction: column;
    overflow: visible;
  }

  .main-content {
    padding-top: 20px;
    padding-bottom: 80px; /* Space for bottom action bar */
    justify-content: flex-start; /* Prevent cut-off at top when small */
  }

  .wheel-container {
    width: 90%;
    max-width: 320px;
    margin-top: auto;
    margin-bottom: auto;
  }

  #fullscreen-toggle {
    display: none !important;
  }

  /* Bottom Action Bar */
  .sidebar-toggle-btn {
    position: fixed;
    bottom: 0;
    top: auto;
    border-radius: 0;
    width: 50%;
    padding: 16px;
    background: var(--bg-panel);
    border: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 50;
  }

  .history-pos {
    left: 0;
    right: auto;
    border-right: 1px solid var(--border);
  }

  .settings-pos {
    right: 0;
    left: auto;
  }

  /* Bottom Sheet Sidebar */
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0; /* Cover full width natively */
    width: 100%;
    height: 75vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.1);
    z-index: 100;
    padding: 24px 20px;
  }

  .right-sidebar.hidden {
    transform: translateY(100%);
  }

  #winner-name {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
  }

  .modal {
    padding: 30px 20px;
    width: 90%;
  }
}
