/* Português a Valer — Mini App "Azulejo".
   Palette: azulejo pigments. Cobalt on tin-glaze white; copper green, manganese, antimony ochre. */

:root {
  --glaze: #f4f5f1;
  --paper: #fbfbf9;
  --wash: #dfe6f3;
  --cobalt: #1d3f96;
  --ink: #142a63;
  --muted: #56648a;
  --line: #ccd5e7;
  --copper: #2c7a57;
  --copper-wash: #dcefe4;
  --manganese: #8a2a4a;
  --manganese-wash: #f4e1e8;
  --ochre: #b8860b;
  --on-cobalt: #f4f5f1;
  --shadow: 0 1px 0 rgba(20, 42, 99, 0.06), 0 12px 32px -18px rgba(20, 42, 99, 0.35);

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;

  --gutter: 16px;
  --tabs-height: 64px;
  --safe-top: max(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px), env(safe-area-inset-top, 0px));
  --safe-bottom: max(var(--tg-content-safe-area-inset-bottom, 0px) + var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));

  color-scheme: light;
}

:root[data-theme="dark"] {
  --glaze: #0d1834;
  --paper: #13224a;
  --wash: #1b2d5c;
  --cobalt: #8daef7;
  --ink: #e3eafb;
  --muted: #9cabcf;
  --line: #2a3d70;
  --copper: #6fd1a0;
  --copper-wash: #163f35;
  --manganese: #f29cb9;
  --manganese-wash: #47203b;
  --ochre: #e8b93a;
  --on-cobalt: #0d1834;
  --shadow: 0 12px 32px -18px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--glaze);
  color: var(--ink);
  font: 400 17px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 50;
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}

button, input { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }

[hidden] { display: none !important; }

/* ---------- Frame ---------- */

/* A cercadura (border-tile strip). The mask keeps the cobalt color of the theme. */
.frieze { padding-top: var(--safe-top); }

.frieze::after {
  --strip: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='14' viewBox='0 0 28 14'><path d='M0 0h28v2H0z'/><path d='M2 14a12 12 0 0 1 24 0h-4a8 8 0 0 0-16 0z'/><circle cx='14' cy='10' r='2.2'/><circle cx='0' cy='7' r='1.6'/><circle cx='28' cy='7' r='1.6'/></svg>");
  content: "";
  display: block;
  height: 14px;
  background: var(--cobalt);
  opacity: 0.85;
  -webkit-mask: var(--strip) repeat-x left top / 28px 14px;
          mask: var(--strip) repeat-x left top / 28px 14px;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px var(--gutter) calc(var(--tabs-height) + var(--safe-bottom) + 32px);
  outline: none;
}

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-height) + var(--safe-bottom));
  padding: 0 max(0px, calc((100% - 560px) / 2)) var(--safe-bottom);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 10;
}

.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.tabs svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.tabs a[aria-current="page"] { color: var(--cobalt); }
.tabs a[aria-current="page"] svg { fill: color-mix(in srgb, var(--cobalt) 18%, transparent); }

/* ---------- Shared parts ---------- */

.lede { color: var(--muted); margin: 8px 0 0; max-width: 34em; }

.section-heading {
  font-size: 22px;
  margin: 36px 0 4px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: var(--cobalt);
  color: var(--on-cobalt);
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

.button:active { transform: scale(0.98); }
.button:disabled { opacity: 0.5; cursor: default; }

.button-quiet {
  background: transparent;
  color: var(--cobalt);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.button-row { display: flex; gap: 10px; margin-top: 20px; }
.button-row .button { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: var(--on-cobalt);
}

.notice {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--ochre);
  background: color-mix(in srgb, var(--ochre) 12%, var(--paper));
  border-radius: 0 8px 8px 0;
}

.state {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}
.state h1 { color: var(--ink); font-size: 26px; margin-bottom: 8px; }
.state .button { margin-top: 20px; }

.tile { display: block; color: var(--cobalt); }
.tile .tile-bg { fill: var(--wash); }
.tile .ring-on { fill: var(--cobalt); }
.tile .ring-off { fill: var(--line); }

/* ---------- Home ---------- */

.hello h1 {
  font-size: clamp(34px, 10vw, 44px);
  font-weight: 650;
  font-variation-settings: "SOFT" 100, "opsz" 144;
  letter-spacing: -0.01em;
}

.hello .button { margin-top: 20px; width: 100%; }

.units { list-style: none; margin: 8px 0 0; padding: 0; }

.unit {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 16px;
  align-items: center;
  width: 100%;
  padding: 16px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.units li:last-child .unit { border-bottom: 0; }

.unit-name {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.unit-title {
  display: block;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--muted);
  margin: 2px 0 6px;
}

.unit-stats { display: block; font-size: 14px; color: var(--muted); }
.unit-stats b { color: var(--ink); font-weight: 700; }

.badge {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  color: var(--ochre);
  border: 1.5px solid currentColor;
  border-radius: 999px;
  padding: 1px 8px;
}

.unit .tile { width: 76px; height: 76px; }

/* ---------- Quiz ---------- */

.quiz-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.quiz-head .tile { width: 40px; height: 40px; flex: none; }
.quiz-head h1 { font-size: 20px; }
.quiz-topic { display: block; font-family: var(--font-display); font-style: italic; color: var(--muted); font-size: 15px; }

.plaque {
  position: relative;
  padding: 22px 20px 24px;
  background: var(--paper);
  border: 1.5px solid var(--cobalt);
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 0 0 4px var(--paper), inset 0 0 0 5px color-mix(in srgb, var(--cobalt) 45%, transparent);
}

.instruction { margin: 0 0 12px; color: var(--muted); font-size: 15px; }

.prompt {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(22px, 6.4vw, 28px);
  line-height: 1.3;
  font-weight: 500;
  font-variation-settings: "opsz" 72;
}

.blank {
  display: inline-block;
  min-width: 3.2em;
  padding: 0 4px;
  border-bottom: 2px solid var(--cobalt);
  text-align: center;
}

.blank.filled {
  border-bottom-color: var(--copper);
  color: var(--copper);
  font-style: italic;
  animation: fill 420ms cubic-bezier(.2, .8, .2, 1);
}

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

.answers { display: grid; gap: 10px; margin-top: 18px; }

.answer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 12px 18px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  font-size: 18px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.answer:not(:disabled):active { border-color: var(--cobalt); }
.answer:disabled { cursor: default; }
.answer.is-correct { border-color: var(--copper); background: var(--copper-wash); color: var(--copper); }
.answer.is-wrong { border-color: var(--manganese); background: var(--manganese-wash); color: var(--manganese); }
.answer.is-dim { opacity: 0.55; }
.answer .mark { font-size: 15px; font-weight: 700; }

.result { margin: 16px 0 0; font-weight: 600; }
.result.good { color: var(--copper); }
.result.bad { color: var(--manganese); }

/* ---------- Study ---------- */

.unit-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.section-list { list-style: none; margin: 0; padding: 0; }

.section-link {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.section-link .num {
  flex: none;
  width: 1.6em;
  font-family: var(--font-display);
  color: var(--cobalt);
  font-variant-numeric: tabular-nums;
}

/* Section text from the server (md_to_web_html). */
.prose { line-height: 1.6; }
.prose h3 { font-size: 26px; margin: 0 0 12px; }
.prose h4 { font-size: 18px; margin: 24px 0 8px; color: var(--cobalt); }
.prose p { margin: 0 0 12px; max-width: 36em; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 1.3em; }
.prose li { margin: 4px 0; }
.prose li::marker { color: var(--cobalt); }
.prose li.sub { margin-left: 1.2em; list-style-type: circle; }
.prose i { font-family: var(--font-display); font-size: 1.04em; }
.prose b { font-weight: 700; }
.prose s { color: var(--manganese); }
.prose blockquote {
  margin: 0 0 12px;
  padding: 8px 14px;
  border-left: 3px solid var(--ochre);
  color: var(--muted);
}

.prose table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  margin: 8px 0 16px;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.4;
  -webkit-overflow-scrolling: touch;
}

.prose th, .prose td {
  padding: 8px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  min-width: 7em;
}

.prose th { background: var(--wash); font-weight: 700; }
.prose tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--wash) 35%, transparent); }

/* ---------- Schedule ---------- */

.field { margin-top: 28px; }
.field-label { display: block; font-weight: 700; margin-bottom: 10px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 16px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 14px;
}

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 160ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 160ms ease;
}

.switch:checked { background: var(--cobalt); }
.switch:checked::after { transform: translateX(20px); }

.days { display: flex; flex-wrap: wrap; gap: 8px; }
.days .chip { min-width: 56px; justify-content: center; }

.time-input {
  min-height: 52px;
  padding: 0 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-family: var(--font-display);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.hint { margin: 10px 0 0; color: var(--muted); font-size: 14px; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled { opacity: 0.45; }

/* ---------- Sheet and toast ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 18, 42, 0.45);
  z-index: 20;
}

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  max-height: 86vh;
  overflow-y: auto;
  padding: 10px var(--gutter) calc(20px + var(--safe-bottom));
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  border-top: 3px solid var(--cobalt);
  z-index: 21;
  animation: rise 260ms cubic-bezier(.2, .8, .2, 1);
}

.sheet > * { max-width: 560px; margin-left: auto; margin-right: auto; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin-bottom: 14px; }
.sheet-title { font-size: 15px; font-family: var(--font-body); color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.sheet-close { display: flex; width: 100%; margin-top: 8px; }

@keyframes rise {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-height) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--glaze);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
