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

:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --primary: #0b4f6c;
  --primary-soft: #e6f0f5;
  --text: #0f172a;
  --muted: #475569;
  --danger: #b91c1c;
  --ok: #166534;
  --warn: #9a3412;
  --border: #dbe3ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* Roboto for Android/Huawei, -apple-system/BlinkMacSystemFont for iOS/macOS,
     Segoe UI for Windows — falls back to system sans-serif everywhere */
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #e8f1f8 0%, var(--bg) 35%, var(--bg) 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent any element from causing horizontal scroll */
  overflow-x: hidden;
}

/* Remove the gray tap flash on Android Chrome; use :active for feedback instead */
a, button, select, input, label {
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  /* Use env() safe-area insets so content isn't hidden behind notches/home bars
     on iPhone X+ and notched Android/Huawei devices */
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  display: grid;
  gap: 1rem;
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.hero h1 {
  margin: 0;
  font-size: 2rem;
  color: var(--primary);
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44px meets both iOS HIG and Android 48dp touch target guidelines */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #c8dbe7;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s;
}

.info-btn:hover {
  background: #d0e6f0;
}

.hero p {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

h2 {
  margin: 0 0 0.8rem;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.results-header h2 {
  margin: 0;
}

.pdf-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: auto;
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  margin-top: 0;
  white-space: nowrap;
}

.label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

select,
input,
button {
  width: 100%;
  /* Force 1rem (16px) so iOS Safari does NOT zoom in on focus */
  font-size: 1rem;
  font-family: inherit;
  border-radius: 10px;
  /* Remove browser-native styling (important on Android/Samsung Internet) */
  -webkit-appearance: none;
  appearance: none;
}

select,
input {
  border: 1px solid var(--border);
  background: #fff;
  padding: 0.7rem;
  color: var(--text);
  /* Let text truncate instead of overflowing */
  text-overflow: ellipsis;
}

/* Custom dropdown arrow — replaces the OS-native one stripped by appearance:none */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230b4f6c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  padding-right: 2.5rem;
}

button {
  border: 0;
  padding: 0.75rem;
  /* Ensure every button meets the 44px minimum touch target (iOS HIG + Android) */
  min-height: 44px;
  margin-top: 0.75rem;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.25;
}

button:active {
  opacity: 0.82;
}

button.secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #c8dbe7;
}

button.danger {
  background: #fff5f5;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.subjects {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.subject-row {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 1fr 110px;
}

.subject-row .subject-search,
.subject-row .subject-select,
.subject-row .mark-input {
  grid-column: 1 / -1;
}

.subject-row .remove-subject {
  grid-column: 1 / -1;
  margin-top: 0;
}

.errors {
  color: var(--danger);
  font-weight: 600;
  margin-bottom: 0.7rem;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.university-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 0.7rem;
}

.accordion-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  padding: 0.9rem;
  /* Reset button base overrides that don't apply here */
  margin-top: 0;
  min-height: 52px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 1rem;
}
.accordion-toggle:hover {
  background: var(--primary-soft);
}
.accordion-uni-name {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
  word-break: break-word;
  min-width: 0; /* allow flex child to shrink below content size */
}
.accordion-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.accordion-chevron {
  color: var(--primary);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}
.accordion-toggle[aria-expanded="true"] .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-programme-list {
  list-style: none;
  margin: 0;
  padding: 0 0.9rem 0.9rem;
}
.accordion-programme {
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}
.accordion-programme-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
  word-break: break-word;
}

.university-header {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: baseline;
}

.badge {
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  background: #eef2ff;
}

.ok {
  color: var(--ok);
}

.warn {
  color: var(--warn);
}

.small {
  font-size: 0.9rem;
  color: var(--muted);
}

ul {
  margin: 0.45rem 0 0;
  padding-left: 1rem;
}

.stream-badge {
  font-size: 0.78rem;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-weight: 500;
}

.subject-reqs {
  margin-top: 0.35rem;
  padding: 0.45rem 0.6rem;
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
}

.subject-reqs-label {
  font-weight: 600;
  color: var(--primary);
  display: block;
  margin-bottom: 0.2rem;
}

.subject-req-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text);
}

.subject-req-list li {
  margin-bottom: 0.1rem;
}

.muted {
  color: var(--muted);
  font-style: italic;
}

@media (min-width: 720px) {
  .subject-row {
    grid-template-columns: 1fr 1fr 120px 100px;
    align-items: center;
  }

  .subject-row .subject-search,
  .subject-row .subject-select,
  .subject-row .mark-input {
    grid-column: auto;
  }

  .subject-row .remove-subject {
    grid-column: auto;
  }
}

/* Landscape phones — reduce top/bottom padding so content is easier to scroll */
@media (max-height: 500px) and (orientation: landscape) {
  .container {
    gap: 0.65rem;
  }
  .card {
    padding: 0.75rem;
  }
}

/* ── Screen visibility ───────────────────────────────────────────── */
.screen {
  display: none;
}
.screen.active {
  display: block;
}

/* ── Action buttons row (Screen 4 top) ──────────────────────────── */
.action-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.action-btn-row button {
  margin-top: 0;
}

/* ── Screen divider ──────────────────────────────────────────────── */
.screen-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0 0;
}

/* ── Screen 5: Improvement rows ─────────────────────────────────── */
.improve-row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.improve-subject {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.improve-detail {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.improve-marks {
  color: var(--primary);
  font-weight: 500;
}
.improve-unlock {
  color: var(--ok);
  font-weight: 600;
  font-size: 0.88rem;
}

/* ── Screen 6: Chances ───────────────────────────────────────────── */
.chances-uni-header {
  padding: 0.6rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.chances-programme {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}
.chances-prog-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
  word-break: break-word;
}
.chances-reason {
  margin: 0.15rem 0 0.4rem;
  color: var(--warn);
}

/* ── APS Screen (Screen 3) ───────────────────────────────────────── */
.aps-uni-list {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.aps-uni-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.aps-uni-name {
  font-weight: 500;
  color: var(--text);
}
.aps-uni-score {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.private-unis-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.2rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--primary-soft);
}

/* Very small screens (< 360px — some older Huawei/Android models) */
@media (max-width: 359px) {
  .accordion-toggle {
    font-size: 0.92rem;
    padding: 0.75rem;
  }
  .hero h1 {
    font-size: 1.6rem;
  }
  .badge {
    font-size: 0.78rem;
    padding: 0.15rem 0.4rem;
  }
}

/* ── Google AdSense ad containers ── */
.ad-container {
  margin: 0.75rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

/* ── Cookie consent banner ── */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--primary);
  color: #ffffff;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  z-index: 9999;
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.15);
}

.cookie-banner p {
  margin: 0;
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.4;
  min-width: 0;
}

.cookie-banner a {
  color: #ffffff;
  text-decoration: underline;
}

.cookie-banner a:hover {
  opacity: 0.85;
}

.cookie-banner button {
  background: #ffffff;
  color: var(--primary);
  border: none;
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  flex-shrink: 0;
}

.cookie-banner button:hover {
  background: var(--primary-soft);
}
