:root {
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #16191d;
  --muted: #5d6670;
  --line: #d9dee3;
  --accent: #0f766e;
  --accent-soft: #e3f2f0;
  --accent-text: #ffffff;
  --rec: #d32f2f;
  --rec-soft: rgba(211, 47, 47, .22);
  --error: #b42318;
  --ok: #157f3d;
  --warn-bg: #fff4e5;
  --warn: #8a4b00;
  --kvkk: #eef6f5;
  --fresh: #e8f6ee;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --card: #1a1e21;
    --text: #e8eaec;
    --muted: #9aa4ad;
    --line: #2d3338;
    --accent: #2bb3a5;
    --accent-soft: #173431;
    --accent-text: #08201d;
    --rec: #ef5350;
    --rec-soft: rgba(239, 83, 80, .25);
    --error: #ff8a80;
    --ok: #5fd38d;
    --warn-bg: #3a2a12;
    --warn: #ffcc80;
    --kvkk: #17282a;
    --fresh: #173324;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

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

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.brand { font-weight: 700; color: var(--accent); letter-spacing: .02em; }
.who { color: var(--muted); font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px 16px; }

h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.lead { color: var(--muted); margin: 0 0 16px; }

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.opt { font-weight: 400; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type=text], input[type=password], select {
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}

.kvkk { background: var(--kvkk); border-radius: 12px; padding: 12px; font-size: 14px; }
.kvkk p { margin: 6px 0 10px; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 600; }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }

button { font: inherit; cursor: pointer; border: 0; border-radius: 12px; min-height: 48px; color: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.primary:disabled { opacity: .6; }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); padding: 0 14px; width: 100%; }
.link { background: none; color: var(--muted); text-decoration: underline; min-height: 40px; padding: 0 8px; }

.error { color: var(--error); margin: 0; min-height: 1.5em; font-size: 14px; }

.token-known { color: var(--ok); font-size: 14px; margin: 0; }
.token-known .link { color: var(--muted); min-height: 32px; }

/* ---- reading ---- */

.meta { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.env { flex: 1; max-width: 200px; }
.progress { flex: 1; max-width: 160px; text-align: right; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.redo {
  margin-top: 16px;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.redo .link { color: var(--warn); flex: none; }

.category { margin: 18px 0 4px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.sentence { font-size: 26px; line-height: 1.35; font-weight: 600; margin: 0; min-height: 2.7em; overflow-wrap: anywhere; }

.recorder { display: flex; flex-direction: column; align-items: center; padding: 20px 0 4px; }

.mic {
  position: relative;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .28);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mic .icon { width: 44px; height: 44px; fill: currentColor; position: relative; z-index: 1; }
.mic .i-stop, .mic .spinner { display: none; }
.mic .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--rec-soft);
  transform: scale(calc(1 + var(--level, 0) * .45));
  opacity: 0;
  transition: transform 80ms linear;
}

.mic[data-state=recording] { background: var(--rec); color: #fff; box-shadow: 0 6px 18px var(--rec-soft); }
.mic[data-state=recording] .i-mic { display: none; }
.mic[data-state=recording] .i-stop { display: block; }
.mic[data-state=recording] .ring { opacity: 1; }

.mic[data-state=saving] { background: var(--line); color: var(--muted); box-shadow: none; cursor: progress; }
.mic[data-state=saving] .i-mic { display: none; }
.mic[data-state=saving] .spinner {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid currentColor;
  border-right-color: transparent;
  animation: spin .8s linear infinite;
}

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

.rec-hint { margin: 14px 0 0; font-weight: 600; text-align: center; }
.timer { margin: 2px 0 0; min-height: 1.5em; color: var(--rec); font-variant-numeric: tabular-nums; font-weight: 600; }
.status { min-height: 1.5em; margin: 4px 0 0; text-align: center; font-size: 15px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--error); }

.hint { color: var(--muted); font-size: 14px; margin: 12px 0 0; text-align: center; }
.skip { display: block; margin: 8px auto 0; }

/* ---- table ---- */

.count { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 10px; font-size: 14px; }
.empty { color: var(--muted); margin: 0; font-size: 15px; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 0 4px 8px; border-bottom: 1px solid var(--line); }
td { padding: 10px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
th.act, td.act { width: 1%; white-space: nowrap; text-align: right; }
td.text .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.badge { display: inline-block; margin-top: 4px; font-size: 12px; background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 0 6px; }

tr.fresh td { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: var(--fresh); } to { background: transparent; } }

.ib {
  width: 40px;
  height: 40px;
  min-height: 40px;
  border-radius: 10px;
  background: transparent;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}
.ib svg { width: 22px; height: 22px; fill: currentColor; }
.ib:hover { background: var(--bg); color: var(--text); }
.ib.play { color: var(--accent); }
.ib.del:hover { color: var(--error); }
.ib .i-pause { display: none; }
.ib.playing .i-play { display: none; }
.ib.playing .i-pause { display: block; }
.ib:disabled { opacity: .4; cursor: default; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

footer { margin-top: auto; padding-top: 8px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .mic .ring, #progress-fill { transition: none; }
  tr.fresh td { animation: none; }
  .mic[data-state=saving] .spinner { animation-duration: 2s; }
}

[hidden] { display: none !important; }
