@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600;700&family=Space+Mono:wght@400;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --gold: #D4A017;
  --gold-bright: #F5C842;
  --gold-dim: #8B6914;
  --gold-soft: #342814;
  --yellow: #dab016;      
  --green: #126B3A;
  --grey: #222222;
  --green-bright: #1FA85C;
  --green-glow: rgba(31, 168, 92, 0.3);
  --bg: #131512;
  --surface: #1E211C;
  --surface-2: #272B24;
  --surface-3: #31352D;
  --border: rgba(212, 160, 23, 0.35);
  --border-hover: rgba(212, 160, 23, 0.65);
  --text: #EDE9D8;
  --text-dim: #A89E88;
  --text-muted: #6E6860;
  --red: #C0392B;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-gold: 0 0 20px rgba(212,160,23,0.2);
}

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

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg);
  background-image: 
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(26, 140, 78, 0.08) 0%, transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M0 30h60M30 0v60' stroke='rgba(212,160,23,0.04)' stroke-width='1'/%3E%3C/svg%3E");
  color: var(--text);
  min-height: 100vh;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ─── HEADER ─── */
.app-header {
  background: linear-gradient(135deg, #0D1510 0%, #111A0F 100%);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.app-header h1 {
  font-family: 'Rajdhani', sans-serif;
  font-size: clamp(18px, 4vw, 30px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  line-height: 1;
  flex: 1;
}

.header-accent {
  color: var(--gold);
}

.username-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.username-wrapper label {
  font-family: 'Rajdhani', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: block;
  margin: 0;
}

.username-wrapper input[type="text"] {
  width: 130px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.username-wrapper input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.12);
}

/* ─── MAIN CONTENT ─── */
.main-content {
  padding: 16px;
  max-width: 860px;
  margin: 0 auto;
}

/* ─── MAIN TABS ─── */
.main-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 5px;
}

.main-tab {
  padding: 10px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.2s;
}

.main-tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.main-tab.active {
  background: var(--green);
  color: var(--gold-bright);
  box-shadow: 0 0 12px rgba(26,140,78,0.3);
}

/* ─── SUB TABS ─── */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.sub-tabs::-webkit-scrollbar { display: none; }

.sub-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all 0.2s;
  white-space: nowrap;
}

.sub-tab:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.sub-tab.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold-bright);
}

/* ─── TAB CONTENT ─── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── MATCH INFO GRID ─── */
.match-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.match-info-grid .span-2 {
  grid-column: span 2;
}

/* ─── CARDS / SECTIONS ─── */
.card {
  background: var(--surface);
  border: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 12px;
}

.card-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 14px;
  background: var(--gold);
  border-radius: 2px;
}

/* ─── FORM GROUPS ─── */
.form-group {
  margin-bottom: 18px;
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238A8578' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.1);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

/* ─── TOGGLE PILLS ─── */
.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle-label {
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="radio"],
.toggle-label input[type="checkbox"] {
  display: none;
}

.toggle-pill {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.18s;
  white-space: nowrap;
}

.toggle-label input:checked + .toggle-pill {
  background: var(--green);
  border-color: var(--green-bright);
  color: #fff;
  box-shadow: 0 0 10px var(--green-glow);
}

.toggle-label:hover .toggle-pill {
  border-color: var(--border-hover);
  color: var(--text);
}

/* ─── COUNTERS ─── */
.counter {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.counter-label {
  flex: 1;
  padding: 10px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.counter-value {
  font-family: 'Space Mono', monospace;
  font-size: 20px;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
  color: var(--gold-bright);
  padding: 0 4px;
}

.counter-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.counter-btn:first-of-type {
    border-radius: 10px;
}

.counter-btn:hover {
  background: var(--green);
  color: #fff;
}

.counter-btn:active {
  background: var(--green-bright);
}

/* 5 buttons: [-5][-][val][+][+5] */
.counter-btn.big-step {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-dim);
  background: var(--surface-2);
}
.counter-btn.big-step:hover {
  color: #fff;
}

/* ─── SLIDERS ─── */
.slider-container {
  padding: 6px 0 0;
}

.styled-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border);
}

.styled-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  background: var(--gold);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid var(--bg);
  box-shadow: 0 0 8px rgba(212,160,23,0.4);
  transition: transform 0.15s;
}

.styled-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.styled-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: var(--gold);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid var(--bg);
  box-shadow: 0 0 8px rgba(212,160,23,0.4);
}

.slider-notches {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  font-family: 'Space Mono', monospace;

  padding-left: 18px;
  padding-right: 0px;
}

@media (max-width: 600px) {
  .slider-notches {
    font-size: 9px;
  }
}

/* ─── ACTION BUTTONS ─── */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
  padding-bottom: 24px;
}

.btn {
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.2s;
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-3);
}

.btn-primary {
  background: linear-gradient(135deg, var(--green), var(--green-bright));
  color: #fff;
  box-shadow: 0 4px 14px rgba(26,140,78,0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(26,140,78,0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-danger {
  background: var(--surface-2);
  border: 1px solid rgba(192,57,43,0.3);
  color: #E57373;
}

.btn-danger:hover {
  background: rgba(192,57,43,0.15);
  border-color: rgba(192,57,43,0.6);
}

/* ─── HISTORY ─── */
.history-section-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.history-stat {
  font-family: 'Space Mono', monospace;
  font-size: 24px;
  font-weight: 700;
  color: var(--gold-bright);
  display: inline;
}

.history-stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 6px;
}

.history-button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (min-width: 480px) {
  .history-button-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.history-button,
.match-button {
  width: 100%;
  padding: 11px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  line-height: 1.4;
  transition: all 0.18s;
  text-align: center;
}

.history-button:hover,
.match-button:hover {
  background: var(--green);
  border-color: var(--green-bright);
  color: #fff;
}

.history-count-bar {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 14px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ─── MODAL ─── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: var(--shadow);
}

.modal-content h2 {
  font-family: 'Rajdhani', sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold-bright);
  margin-bottom: 16px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

#qrcode {
  background: #fff;
  padding: 12px;
  border-radius: var(--radius);
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 12px;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
}

#qrcode img,
#qrcode canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 10px;
}

details {
  border: 1px solid #ccc;
  display: inline-block;
  font-size: small;
  border-radius: 5px;
  padding: 10px;
  margin-bottom: 10px;
}

/* ─── EXPORT BUTTONS ─── */
.export-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.export-buttons .btn {
  min-width: 160px; /* ← Add this line */
}

@media (min-width: 400px) {
  .export-buttons {
    flex-direction: row;
    flex-wrap: wrap; /* ← Add this so buttons wrap */
  }
}

/* ─── MATCH STAGE ─── */
.stage-group {
  display: flex;
  gap: 8px;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 400px) {
  .match-info-grid {
    grid-template-columns: 1fr;
  }
  .match-info-grid .span-2 {
    grid-column: span 1;
  }
  .action-buttons {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 600px) {
  body {
    padding: 0;
  }
  .main-content {
    padding: 24px 32px;
  }
  .card {
    padding: 24px;
  }
  .app-header {
    padding: 18px 32px 16px;
  }
  .main-tab {
    font-size: 16px;
    padding: 12px;
  }
  .sub-tab {
    font-size: 15px;
    padding: 10px 20px;
  }
  label {
    font-size: 12px;
  }
  input[type="text"],
  input[type="number"],
  textarea,
  select {
    font-size: 15px;
    padding: 11px 14px;
  }
  .counter-label {
    font-size: 15px;
    padding: 12px 16px;
  }
  .counter-btn {
    width: 50px;
    height: 50px;
    font-size: 18px;
  }
  .counter-btn.big-step {
    font-size: 12px;
  }
  .counter-value {
    font-size: 24px;
    min-width: 56px;
  }
  .toggle-pill {
    font-size: 14px;
    padding: 9px 16px;
  }
  .btn {
    font-size: 16px;
    padding: 14px 24px;
  }
  .card-title {
    font-size: 14px;
  }
}

/* Delete buttons appended into modal by pastMatchesQR() */
#qrModal > .match-button {
  display: block;
  margin: 6px auto 0;
  max-width: 200px;
  background: rgba(192,57,43,0.12);
  border-color: rgba(192,57,43,0.4);
  color: #E57373;
}

#qrModal > .match-button:hover {
  background: rgba(192,57,43,0.25);
  border-color: rgba(192,57,43,0.7);
  color: #fff;
}
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid #d0d5dd;
    font-weight: 700;
    padding: 0;
    line-height: 30px;
    text-align: center;
}

#qrcode{
    background: #ffffff;
    padding: 12px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
}

.alert {
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #d0d5dd;
}

.config {
    border: 1px solid #d0d5dd;
    padding: 20px;
    margin-bottom: 20px;
}

.history-button{
    width: 100%;
    padding: 10px 20px;
    border: 1px solid #d0d5dd;
    background: #fff;
    cursor: pointer;
    border-radius: 12px;
}

.history-button:hover {
    background-color: #156B3A;
    transition: background 0.2s, color 0.2s;
}

.history-button-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 10px
}

@media (max-width: 700px) {
    .history-button-grid {
        grid-template-columns: repeat(2, minmax(0,1fr));
    }
}

.match-stage-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.validation-modal-content {
    background: var(--grey);
    color: var(--yellow);
    border: 2px solid var(--yellow);
    border-radius: 16px;
    padding: 28px 22px 22px;
    max-width: 460px;
    width: 92%;
    text-align: center;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
}

.validation-modal-icon {
    font-size: 36px;
    margin-bottom: 6px;
}

.validation-modal-title {
    margin-bottom: 18px;
    font-size: 20px;
    color: var(--yellow);
}

.validation-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0 8px 0;
    text-align: left;
}

.validation-section-badge {
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.required-badge {
    background: #e05252;
    color: #fff;
}

.warning-badge {
    background: var(--yellow);
    color: #000;
}

.validation-section-sub {
    font-size: 12px;
    color: rgba(255,255,255,0.55);
    font-weight: 400;
}

.validation-error-list {
    list-style: none;
    padding: 0;
    margin: 0 0 10px 0;
    text-align: left;
}

.validation-error-list li {
    border-radius: 8px;
    padding: 9px 12px;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--white);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.4;
}

.validation-error-list li.error-item {
    background: rgba(224, 82, 82, 0.12);
    border: 1px solid rgba(224, 82, 82, 0.45);
}

.validation-error-list li.error-item::before {
    content: "✕";
    color: #e05252;
    font-weight: 900;
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 1px;
}

.validation-error-list li.warning-item {
    background: rgba(218, 176, 22, 0.1);
    border: 1px solid rgba(218, 176, 22, 0.35);
}

.validation-error-list li.warning-item::before {
    content: "!";
    color: var(--yellow);
    font-weight: 900;
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 1px;
    width: 13px;
    text-align: center;
}

.validation-modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 18px;
}

.validation-ok-btn {
    background: var(--green);
    color: var(--white);
    border: 2px solid var(--green);
    border-radius: 999px;
    padding: 10px 26px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.validation-ok-btn:hover {
    background: #1a8a4a;
}

.validation-cancel-btn {
    background: transparent;
    color: var(--yellow);
    border: 2px solid var(--yellow);
    border-radius: 999px;
    padding: 10px 26px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.validation-cancel-btn:hover {
    background: rgba(218, 176, 22, 0.15);
}
