:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #d9d9de;
  --accent: #0a66d8;
  --danger: #d23b30;
  --new: #0a66d8;
  --learn: #d23b30;
  --review: #1e8e3e;
  --card-bg: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: #38383a;
    --accent: #4c9bff;
    --danger: #ff6259;
    --new: #4c9bff;
    --learn: #ff6259;
    --review: #3fc463;
    --card-bg: #1c1c1e;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

#bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  min-height: 52px;
}

#title {
  grid-column: 2;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
}

#back {
  grid-column: 1;
  justify-self: start;
}

#bar-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 4px;
}

.bar-btn {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 8px 6px;
  min-height: 44px;
  white-space: nowrap;
}

.bar-btn:disabled {
  color: var(--muted);
  opacity: 0.5;
}

#main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 24px;
}

#main.flush {
  padding: 0;
  display: flex;
  flex-direction: column;
}

#foot:empty {
  display: none;
}

#foot {
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

#nav {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}

#nav button {
  flex: 1;
  background: none;
  border: 0;
  padding: 6px 0 4px;
  min-height: 50px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

#nav button span {
  font-size: 20px;
  line-height: 1.1;
}

#nav button.on {
  color: var(--accent);
}

/* Listas */

.group {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  margin: 0 0 20px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.group > :last-child {
  border-bottom: 0;
}

.row .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row .sub {
  display: block;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row.accent {
  color: var(--accent);
}

.row.danger {
  color: var(--danger);
}

.row input[type="number"] {
  width: 84px;
  text-align: right;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 17px;
}

.row input[type="checkbox"] {
  width: 22px;
  height: 22px;
}

.counts {
  display: flex;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.c-new {
  color: var(--new);
}

.c-learn {
  color: var(--learn);
}

.c-review {
  color: var(--review);
}

.zero {
  opacity: 0.35;
}

.label {
  margin: 0 0 6px 14px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.note {
  margin: -12px 14px 20px;
  font-size: 13px;
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px 24px;
}

.empty h2 {
  color: var(--text);
  font-size: 20px;
  margin: 0 0 6px;
}

.banner {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: 15px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.banner button {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 0 4px;
  font-size: 18px;
}

/* Botões */

.btn {
  display: block;
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  margin-bottom: 10px;
}

.btn.plain {
  background: var(--surface);
  color: var(--accent);
  font-weight: 400;
}

.btn:disabled {
  opacity: 0.45;
}

.summary {
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-radius: 12px;
  padding: 16px 8px;
  margin-bottom: 20px;
  text-align: center;
}

.summary b {
  display: block;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.summary span {
  font-size: 13px;
  color: var(--muted);
}

/* Estudo */

#card-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card-bg);
}

.study-counts {
  display: flex;
  gap: 12px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  padding: 8px 6px;
}

.study-counts .cur {
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

.answers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.answers button {
  min-height: 56px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
}

.answers small {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}

.a-again {
  color: var(--danger);
}

.a-good {
  color: var(--review);
}

.a-easy {
  color: var(--accent);
}

#foot .btn {
  margin: 0;
  min-height: 56px;
}

/* Editor */

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 4px 4px 14px;
  font-size: 13px;
  color: var(--muted);
}

.field-tools button {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 4px 8px;
  min-height: 32px;
  font-size: 14px;
}

.field {
  background: var(--surface);
  border-radius: 12px;
  min-height: 64px;
  padding: 12px 14px;
  margin-bottom: 16px;
  outline: none;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
}

.field:focus {
  box-shadow: 0 0 0 2px var(--accent);
}

.field img {
  max-width: 100%;
  height: auto;
}

select,
input[type="text"],
input[type="search"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  background: var(--surface);
  border: 0;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}

/* Sobreposições */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay-box {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px 26px;
  max-width: 280px;
  text-align: center;
}

.overlay-box p {
  margin: 12px 0 0;
  font-size: 15px;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  background: rgba(40, 40, 44, 0.94);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 15px;
  max-width: 86vw;
  text-align: center;
  z-index: 11;
}
