:root {
    --bg: #f5f3ee;
    --card: #ffffff;
    --text: #1f2328;
    --muted: #6b7280;
    --line: #e4e0d8;
    --primary: #0f766e;
    --primary-h: #115e59;
    --bad: #c2410c;
    --ok: #a16207;
    --maybe: #2563eb;
    --good: #15803d;
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16181c;
        --card: #1f2227;
        --text: #e8e6e3;
        --muted: #9aa0a6;
        --line: #33373d;
        --primary: #14b8a6;
        --primary-h: #2dd4bf;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
}
.brand { font-weight: 700; font-size: 20px; color: var(--primary); text-decoration: none; }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar nav a { color: var(--text); text-decoration: none; }
.user { color: var(--muted); }
.inline { display: inline; margin: 0; }

.container { max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; }

h1 { font-size: 26px; margin: 0 0 18px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
}
.center { text-align: center; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 8px 0; }

/* Login */
.login { max-width: 380px; margin: 40px auto; }
label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input:not([type]) {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
}
input[type=number] { max-width: 140px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.wide { width: 100%; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.maybe { background: var(--maybe); border-color: var(--maybe); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
button.link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0; }
button.link:hover { color: var(--text); text-decoration: underline; }
kbd {
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .25);
    font-family: inherit;
}
.btn:not(.primary):not(.bad):not(.ok):not(.maybe):not(.good) kbd { background: var(--line); }

/* Sprachwahl */
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.lang { display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; color: var(--text); }
.lang:hover { border-color: var(--primary); }
.flag { font-size: 48px; }
.lang .name { font-size: 20px; font-weight: 600; }
.lang .meta { font-size: 13px; color: var(--muted); text-align: center; }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab {
    padding: 10px 16px;
    border: none;
    background: none;
    font-size: 16px;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.badge {
    display: inline-block;
    min-width: 24px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--line);
    color: var(--text);
    font-size: 13px;
    text-align: center;
}
.badge.hot { background: var(--primary); color: #fff; }

.direction { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.direction label { display: inline-flex; gap: 6px; align-items: center; margin: 0; color: var(--text); cursor: pointer; }

.panel { margin-top: 4px; }

/* Karte */
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--primary); transition: width .25s; }
.session-info { font-size: 13px; color: var(--muted); margin: 8px 0 18px; }

.question { display: flex; justify-content: center; align-items: center; gap: 12px; min-height: 90px; }
.word { font-size: 34px; font-weight: 600; text-align: center; }
.answer { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 16px; text-align: center; }
.answer-word { font-size: 28px; color: var(--primary); margin-bottom: 12px; }
.sentence { font-size: 18px; margin: 6px 0; }
.sentence.pl { color: var(--muted); font-size: 16px; }

button.icon {
    border: 1px solid var(--line);
    background: var(--bg);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    vertical-align: middle;
}
button.icon.small { width: 34px; height: 34px; font-size: 15px; }

.actions { margin-top: 22px; }
.grades { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stop { display: block; margin: 18px auto 0; }

@media (max-width: 480px) {
    .word { font-size: 28px; }
    .grades { grid-template-columns: 1fr 1fr; }
}

/* Przerwane ćwiczenie */
.resume { border-color: var(--primary); margin-bottom: 14px; }
.resume-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Odłóż na później (powtórki) */
.btn.later { margin-top: 10px; background: transparent; border-style: dashed; color: var(--muted); }
.btn.later:hover { color: var(--text); border-color: var(--muted); }

/* ---------- Postęp ---------- */
h2 { font-size: 19px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
.small { font-size: 13px; }
#progress .card + .card { margin-top: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; align-items: center; padding: 10px 4px; background: var(--bg); border-radius: 10px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); text-align: center; }

.stack-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }
.seg { display: block; height: 100%; }
.seg-retired, .sw-retired { background: var(--good); }
.seg-learning, .sw-learning { background: var(--primary); opacity: .55; }
.seg-new, .sw-new { background: var(--line); }
.stack-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 3px; }
.sw-new { border: 1px solid var(--muted); }

.forecast { display: flex; gap: 6px; align-items: flex-end; height: 130px; }
.fc-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.fc-bar { width: 100%; max-width: 38px; min-height: 2px; background: var(--primary); border-radius: 4px 4px 0 0; }
.fc-num { font-size: 12px; font-weight: 600; }
.fc-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

.intervals { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 5px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 13px; }

.history { list-style: none; padding: 0; margin: 14px 0 0; font-size: 14px; }
.history li { padding: 7px 0; border-top: 1px solid var(--line); }
.h-time { color: var(--muted); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 13px; }

.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input[type=search] { flex: 1; margin: 0; }
input[type=search], select {
    padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--bg); color: var(--text);
}
.word-list { margin-bottom: 12px; }
.w-row {
    display: grid; grid-template-columns: 44px 1fr 150px 90px; gap: 10px; align-items: center;
    padding: 9px 0; border-top: 1px solid var(--line);
}
.w-id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.w-text { display: flex; flex-direction: column; min-width: 0; }
.w-text b { font-weight: 600; overflow-wrap: anywhere; }
.w-pl { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.w-status { display: flex; flex-direction: column; gap: 2px; }
.w-when { font-size: 12px; color: var(--muted); }
.w-act { text-align: right; }
.st { display: inline-block; width: fit-content; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.st-new { background: var(--line); color: var(--text); }
.st-due { background: var(--bad); color: #fff; }
.st-learning { background: var(--primary); color: #fff; }
.st-retired { background: var(--good); color: #fff; }

.danger-zone { border-color: var(--bad); }

/* ---------- Telefon ---------- */
button, a, input, select { touch-action: manipulation; }
body { -webkit-tap-highlight-color: transparent; }

@media (hover: none) and (pointer: coarse) {
    kbd { display: none; }       /* skróty klawiszowe nie mają sensu na telefonie */
}

@media (max-width: 600px) {
    .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
    .topbar nav { gap: 12px; font-size: 14px; }
    .topbar .user { display: none; }
    .container { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
    .page-title { font-size: 22px; margin-bottom: 10px; }
    .card { padding: 16px; border-radius: 12px; }

    .tabs { gap: 0; }
    .tab { flex: 1; padding: 12px 4px; font-size: 15px; text-align: center; }
    .direction { font-size: 13px; gap: 10px; }
    .dir-label { display: none; }
    .wide-mobile { width: 100%; }
    input[type=number] { max-width: none; }

    .question { min-height: 70px; }
    .word { font-size: 30px; }
    .answer-word { font-size: 24px; }
    .sentence { font-size: 17px; }

    /* przyciski odpowiedzi pod kciukiem */
    .actions {
        position: sticky; bottom: 0; z-index: 5;
        background: var(--card);
        margin: 18px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
    }
    .actions .btn { min-height: 54px; font-size: 17px; }
    .grades { grid-template-columns: 1fr 1fr; gap: 8px; }
    .btn.later { min-height: 44px !important; font-size: 15px !important; }
    .stop { margin-top: 26px; }

    .stat-grid { grid-template-columns: repeat(3, 1fr); }
    .stat-value { font-size: 20px; }
    .filters { flex-direction: column; }
    .w-row { grid-template-columns: 1fr auto; grid-template-areas: "text act" "status act"; gap: 4px 10px; }
    .w-id { display: none; }
    .w-text { grid-area: text; }
    .w-status { grid-area: status; flex-direction: row; align-items: center; gap: 8px; }
    .w-act { grid-area: act; }
    .fc-label { font-size: 10px; }
}

/* Nowe słowa: 3 przyciski w jednym rzędzie */
.grades.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 600px) {
    .grades.three { grid-template-columns: repeat(3, 1fr); }
    .grades.three .btn { font-size: 15px; padding: 10px 6px; }
}

.review-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 600px) { .review-actions { flex-direction: column; } }

/* Zdanie odczytywane po "Nie umiem" */
.sentence.playing { background: var(--bg); border-radius: 8px; outline: 2px solid var(--primary); outline-offset: 4px; }

/* ---------- Nowe: własne ćwiczenie i własne słowa ---------- */
#startNew .card + .card { margin-top: 14px; }

.combo { position: relative; }
.combo input { margin-top: 0; }
.combo-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
    max-height: 320px; overflow-y: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.combo-opt {
    display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: baseline;
    padding: 9px 12px; cursor: pointer; border-top: 1px solid var(--line);
}
.combo-opt:first-child { border-top: none; }
.combo-opt.active, .combo-opt:hover { background: var(--bg); }
.combo-opt .o-id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.combo-opt .o-pl { color: var(--muted); font-size: 14px; margin-left: 6px; }
.combo-opt mark { background: none; color: var(--primary); font-weight: 700; }
.combo-empty { padding: 10px 12px; color: var(--muted); font-size: 14px; }
.combo-more { padding: 8px 12px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

.chosen { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; min-height: 4px; }
.pick-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 4px 4px 10px; border-radius: 999px;
    background: var(--bg); border: 1px solid var(--line); font-size: 14px;
}
.pick-chip .c-pl { color: var(--muted); }
.pick-chip button {
    border: none; background: var(--line); color: var(--text); border-radius: 50%;
    width: 22px; height: 22px; line-height: 20px; padding: 0; cursor: pointer; font-size: 14px;
}
.pick-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.tag-custom {
    display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px;
    font-size: 11px; font-weight: 600; background: var(--maybe); color: #fff; vertical-align: 1px;
}

.cf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); cursor: pointer; }
.c-row {
    display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
    padding: 9px 0; border-top: 1px solid var(--line);
}
.c-row.editing { background: var(--bg); }
.c-text { display: flex; flex-direction: column; min-width: 0; }
.c-text b { font-weight: 600; overflow-wrap: anywhere; }
.c-sent { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.c-meta { font-size: 11px; color: var(--muted); }
.c-act { display: flex; gap: 6px; }

@media (max-width: 600px) {
    .cf-grid { grid-template-columns: 1fr; }
    .pick-actions { flex-direction: column; }
    .combo-list { max-height: 50vh; }
    .c-row { grid-template-columns: 1fr; }
}
