/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* Prevent tap highlight on Android/iOS */
  -webkit-tap-highlight-color: transparent;
}

html {
  /* Prevent font size inflation on orientation change (iOS) */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #1a1a2e 0%, #16213e 55%, #0f3460 100%);
  /* Use min-height with dvh (dynamic viewport height) so the address bar is excluded.
     Falls back to 100vh for older browsers. */
  min-height: 100vh;
  min-height: 100dvh;
  color: #fff;
  /* Safe-area padding: handles notch (top) and home bar (bottom) */
  padding: max(16px, env(safe-area-inset-top))
           max(16px, env(safe-area-inset-right))
           max(80px, env(safe-area-inset-bottom))
           max(16px, env(safe-area-inset-left));
  overscroll-behavior: none; /* Prevent pull-to-refresh bounce behind modal */
}

/* ===== Container ===== */
.container {
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Title ===== */
.title {
  text-align: center;
  font-size: clamp(1.2rem, 5vw, 1.7rem);
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 0 20px rgba(229, 57, 53, 0.7);
}

.subtitle {
  text-align: center;
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  font-weight: 500;
  color: #aac4e0;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ===== Ball Display ===== */
.ball-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ball {
  /* Scale ball with viewport — big on large screens, sensible on small ones */
  width: var(--ball-size, clamp(130px, 38vw, 180px));
  height: var(--ball-size, clamp(130px, 38vw, 180px));
  border-radius: 50%;
  /* Default (no number drawn yet) */
  background: radial-gradient(circle at 35% 35%, #78909c, #455a64 60%, #263238);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 30px rgba(69, 90, 100, 0.5),
    0 0 60px rgba(69, 90, 100, 0.2),
    inset 0 -10px 20px rgba(0,0,0,0.3);
  user-select: none;
  flex-shrink: 0;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.ball.pop {
  animation: pop 0.35s ease;
}

@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.22); }
  70%  { transform: scale(0.93); }
  100% { transform: scale(1); }
}

.ball span {
  font-size: var(--ball-font, clamp(2.4rem, 10vw, 3.6rem));
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6), 0 0 4px rgba(0,0,0,0.4);
  line-height: 1;
}

/* Light bands need dark text so the number is readable */
.ball[data-band="2"] span,
.ball[data-band="7"] span,
.ball[data-band="8"] span {
  color: #1a1a1a;
  text-shadow: 0 1px 3px rgba(255,255,255,0.3);
}

.ball-label {
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  color: #aac4e0;
  letter-spacing: 0.5px;
  min-height: 1.4em;
  text-align: center;
}

/* ===== Progress ===== */
.progress-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-text {
  text-align: center;
  font-size: clamp(0.85rem, 3.5vw, 0.95rem);
  color: #aac4e0;
}

.progress-bar-track {
  background: rgba(255,255,255,0.1);
  border-radius: 50px;
  height: 14px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #e53935, #ff6b6b);
  border-radius: 50px;
  width: 0%;
  transition: width 0.4s ease;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Draw button spans full width — big thumb target */
.btn-draw {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, #e53935, #c62828);
  color: #fff;
  box-shadow: 0 6px 20px rgba(229, 57, 53, 0.55);
  font-size: clamp(1rem, 4.5vw, 1.2rem);
  border-radius: 16px;
}

/* Reset + Settings sit side by side */
.controls-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 14px;
  font-size: clamp(0.9rem, 3.8vw, 1rem);
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.4px;
  /* Remove 300ms tap delay on mobile */
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.2s ease, opacity 0.2s;
  /* Minimum touch target per accessibility guidelines */
  min-height: 48px;
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

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

.btn-reset {
  background: linear-gradient(135deg, #546e7a, #37474f);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}

.btn-settings {
  background: linear-gradient(135deg, #1565c0, #0d47a1);
  color: #fff;
  box-shadow: 0 4px 14px rgba(21, 101, 192, 0.5);
}

/* ===== Called Numbers Grid ===== */
.called-section {
  background: rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,0.1);
}

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

.called-section h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: #aac4e0;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.btn-sort {
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  color: #fff;
  box-shadow: 0 3px 10px rgba(46, 125, 50, 0.45);
  padding: 8px 16px;
  font-size: 0.82rem;
  border-radius: 10px;
  min-height: 36px;
}

.btn-sort.sorted {
  background: linear-gradient(135deg, #546e7a, #37474f);
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

.empty-label {
  text-align: center;
  color: rgba(255,255,255,0.25);
  font-size: 0.85rem;
  padding: 10px 0;
}

.empty-label.hidden {
  display: none;
}

.numbers-grid {
  /* Fixed columns that wrap; each chip auto-sizes within the column */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--chip-size, 38px), 1fr));
  gap: 6px;
}

/* ===== Settings select ===== */
.setting-row select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: max(16px, 1rem);
  outline: none;
  touch-action: manipulation;
  transition: border-color 0.2s;
  min-width: 130px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23aac4e0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.setting-row select:focus {
  border-color: #e53935;
}

.setting-row select option {
  background: #1a2744;
  color: #fff;
}

.number-chip {
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--chip-size, 38px);
  font-size: var(--chip-font, clamp(0.65rem, 2.5vw, 0.82rem));
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  animation: chipIn 0.25s ease;
}

/* Light bands — switch chip text to dark */
.number-chip[data-band="2"],
.number-chip[data-band="7"],
.number-chip[data-band="8"] {
  color: #1a1a1a;
  text-shadow: none;
}

/* ===== Colour bands (per decade) ===== */
/* Band colours also applied to the main ball via .ball[data-band] */

[data-band="1"]  { background: radial-gradient(circle at 35% 35%, #ef9a9a, #e53935 60%, #b71c1c); } /* red      1–10  */
[data-band="2"]  { background: radial-gradient(circle at 35% 35%, #80cbc4, #00897b 60%, #004d40); } /* teal     11–20 */
[data-band="3"]  { background: radial-gradient(circle at 35% 35%, #90caf9, #1e88e5 60%, #0d47a1); } /* blue     21–30 */
[data-band="4"]  { background: radial-gradient(circle at 35% 35%, #ce93d8, #8e24aa 60%, #4a148c); } /* purple   31–40 */
[data-band="5"]  { background: radial-gradient(circle at 35% 35%, #ffcc80, #fb8c00 60%, #e65100); } /* orange   41–50 */
[data-band="6"]  { background: radial-gradient(circle at 35% 35%, #f48fb1, #e91e63 60%, #880e4f); } /* pink     51–60 */
[data-band="7"]  { background: radial-gradient(circle at 35% 35%, #a5d6a7, #43a047 60%, #1b5e20); } /* green    61–70 */
[data-band="8"]  { background: radial-gradient(circle at 35% 35%, #ffe082, #fdd835 60%, #f57f17); } /* yellow   71–80 */
[data-band="9"]  { background: radial-gradient(circle at 35% 35%, #bcaaa4, #6d4c41 60%, #3e2723); } /* brown    81–90 */
[data-band="10"] { background: radial-gradient(circle at 35% 35%, #b0bec5, #546e7a 60%, #263238); } /* slate    91+   */

/* Keep the glow on the main ball consistent with its band colour */
.ball[data-band="1"]  { box-shadow: 0 0 30px rgba(229,57,53,0.6),  0 0 60px rgba(229,57,53,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="2"]  { box-shadow: 0 0 30px rgba(0,137,123,0.6),  0 0 60px rgba(0,137,123,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="3"]  { box-shadow: 0 0 30px rgba(30,136,229,0.6), 0 0 60px rgba(30,136,229,0.25), inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="4"]  { box-shadow: 0 0 30px rgba(142,36,170,0.6), 0 0 60px rgba(142,36,170,0.25), inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="5"]  { box-shadow: 0 0 30px rgba(251,140,0,0.6),  0 0 60px rgba(251,140,0,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="6"]  { box-shadow: 0 0 30px rgba(233,30,99,0.6),  0 0 60px rgba(233,30,99,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="7"]  { box-shadow: 0 0 30px rgba(67,160,71,0.6),  0 0 60px rgba(67,160,71,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="8"]  { box-shadow: 0 0 30px rgba(253,216,53,0.6), 0 0 60px rgba(253,216,53,0.25), inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="9"]  { box-shadow: 0 0 30px rgba(109,76,65,0.6),  0 0 60px rgba(109,76,65,0.25),  inset 0 -10px 20px rgba(0,0,0,0.3); }
.ball[data-band="10"] { box-shadow: 0 0 30px rgba(84,110,122,0.6), 0 0 60px rgba(84,110,122,0.25), inset 0 -10px 20px rgba(0,0,0,0.3); }

@keyframes chipIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ===== All-drawn Banner ===== */
.banner {
  text-align: center;
  font-size: clamp(0.95rem, 4vw, 1.1rem);
  font-weight: 700;
  color: #ffd54f;
  letter-spacing: 0.5px;
  padding: 14px 16px;
  background: rgba(255, 213, 79, 0.1);
  border: 1px solid rgba(255, 213, 79, 0.3);
  border-radius: 14px;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Modal (bottom sheet) ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end; /* sheet slides up from the bottom */
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  /* Prevents background page scroll while modal is open */
  overscroll-behavior: contain;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: #1a2744;
  border: 1px solid rgba(255,255,255,0.12);
  /* Rounded only at the top */
  border-radius: 24px 24px 0 0;
  padding: 20px 24px max(28px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 520px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  /* Allow scrolling inside the sheet if content overflows */
  overflow-y: auto;
  max-height: 90dvh;
  max-height: 90vh;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

/* Drag handle indicator */
.modal-handle {
  width: 40px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 24px;
  text-align: center;
}

/* ===== Setting Rows ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-row label {
  font-size: 1rem;
  color: #cdd8e3;
}

.setting-row input[type="number"] {
  width: 88px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1rem;
  text-align: center;
  outline: none;
  /* Prevent iOS zoom on focus (needs font-size >= 16px equivalent) */
  font-size: max(16px, 1rem);
  transition: border-color 0.2s;
  touch-action: manipulation;
}

.setting-row input[type="number"]:focus {
  border-color: #e53935;
}

/* Custom toggle switch instead of checkbox for easier tapping */
.checkbox-row {
  border-bottom: none;
}

.toggle-wrap {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

.toggle-wrap input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.2);
  border-radius: 30px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 4px;
  top: 4px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.toggle-wrap input:checked + .toggle-slider {
  background: #e53935;
}

.toggle-wrap input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ===== Modal Actions ===== */
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.btn-save {
  background: linear-gradient(135deg, #e53935, #c62828);
  color: #fff;
  box-shadow: 0 4px 14px rgba(229,57,53,0.4);
  padding: 15px;
  border-radius: 14px;
}

.btn-cancel {
  background: rgba(255,255,255,0.1);
  color: #cdd8e3;
  padding: 15px;
  border-radius: 14px;
}

/* ===== Landscape phones — more compact layout ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .ball {
    width: clamp(80px, 18vh, 120px);
    height: clamp(80px, 18vh, 120px);
  }
  .ball span {
    font-size: clamp(1.8rem, 6vh, 2.6rem);
  }
  .container {
    gap: 12px;
  }
  .controls {
    flex-direction: row;
    align-items: stretch;
  }
  .btn-draw {
    flex: 1;
    border-radius: 14px;
    padding: 12px;
  }
  .controls-row {
    flex: 1;
    display: grid;
  }
}
