:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f1f4f9;
    --text: #172033;
    --muted: #5f6b80;
    --border: #dfe4ee;
    --primary: #2563eb;
    --primary-ink: #ffffff;
    --primary-soft: #e6eeff;
    --good: #15803d;
    --good-soft: #dcfce7;
    --bad: #b91c1c;
    --bad-soft: #fee2e2;
    --accent: #7c3aed;
    --warn-soft: #fef3c7;
    /* Bulmaca: gazete renkleri */
    --kare-band: #1e88d6;
    --cengel-band: #d93a3a;
    --cell: #ffffff;
    --cell-ink: #111827;
    --cell-black: #141414;
    --cell-empty: #c9ced8;
    --clue-cell: #e3edbf;
    --clue-ink: #1f2a12;
    --arrow: #d93a3a;
    --hl-word: #fff3b0;
    --hl-cell: #ffd54a;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .05);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e131c;
        --surface: #161d29;
        --surface-2: #1d2635;
        --text: #e6eaf2;
        --muted: #9aa6ba;
        --border: #2a3446;
        --primary: #6b9bff;
        --primary-ink: #0b1220;
        --primary-soft: #1c2a47;
        --good: #4ade80;
        --good-soft: #12301f;
        --bad: #f87171;
        --bad-soft: #3a1717;
        --accent: #a78bfa;
        --warn-soft: #3a2f10;
        --cell: #f4f1e8;
        --cell-ink: #111827;
        --cell-black: #05070b;
        --cell-empty: #3a4354;
        --clue-cell: #c9d69a;
        --hl-word: #fde68a;
        --hl-cell: #fbbf24;
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0e131c;
    --surface: #161d29;
    --surface-2: #1d2635;
    --text: #e6eaf2;
    --muted: #9aa6ba;
    --border: #2a3446;
    --primary: #6b9bff;
    --primary-ink: #0b1220;
    --primary-soft: #1c2a47;
    --good: #4ade80;
    --good-soft: #12301f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --accent: #a78bfa;
    --warn-soft: #3a2f10;
    --cell: #f4f1e8;
    --cell-ink: #111827;
    --cell-black: #05070b;
    --cell-empty: #3a4354;
    --clue-cell: #c9d69a;
    --hl-word: #fde68a;
    --hl-cell: #fbbf24;
    --shadow: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- Üst bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1120px; margin: 0 auto; padding: 10px 16px;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 1.1rem; letter-spacing: -.3px; white-space: nowrap; }
.brand span { color: var(--primary); }
.xp-pill {
    margin-left: auto; display: flex; align-items: center; gap: 8px;
    background: var(--primary-soft); color: var(--primary);
    padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: .9rem; white-space: nowrap;
}
.tabs {
    max-width: 1120px; margin: 0 auto; padding: 0 16px;
    display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    border: 0; background: none; padding: 10px 12px; cursor: pointer;
    color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- Kartlar / genel ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 1.15rem; }
.card-head .row { flex-wrap: nowrap; }
.card-head .row input[type="search"] { width: min(240px, 50vw); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 820px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: 10px; border: 1px solid transparent;
    font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--text);
    transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-good { background: var(--good); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input[type="text"], input[type="search"], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); outline: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .tab:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 1px;
}
label.field { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; }
label.field > input, label.field > select { margin-top: 4px; }

/* ---------- Panel ---------- */
.level-badge { padding: 4px 12px; border-radius: 999px; background: var(--good-soft); color: var(--good); font-weight: 700; font-size: .85rem; }
.progress { position: relative; height: 14px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 14px 0 6px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--good)); transition: width .4s; }
.level-marks { position: relative; height: 18px; font-size: .75rem; color: var(--muted); }
.level-marks { margin-bottom: 12px; }
.level-marks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.level-marks span:first-child { transform: none; }
.level-marks span:last-child { transform: translateX(-100%); }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 1.4rem; }
.goal { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.goal:last-child { border-bottom: 0; }
.goal .bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.goal .bar > div { height: 100%; background: var(--good); width: 0; }
.goal .check { width: 22px; text-align: center; }

/* ---------- Bulmaca ---------- */
.mode-switch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
@media (max-width: 720px) { .mode-switch { grid-template-columns: repeat(2, 1fr); } }
.mode-btn {
    text-align: left; border: 2px solid var(--border); border-radius: 12px; padding: 10px 12px;
    background: var(--surface); cursor: pointer;
}
.mode-btn b { display: block; }
.mode-btn small { color: var(--muted); }
.mode-btn[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.mode-btn .done { color: var(--good); font-weight: 700; }

.paper {
    background: #fbfaf6; color: #111; border-radius: 6px; padding: 12px; margin: 0 auto;
    border: 3px solid var(--kare-band); max-width: 760px;
}
.paper.cengel { border-color: var(--cengel-band); max-width: 900px; }
.paper-title {
    text-align: center; color: #fff; background: var(--kare-band);
    font-weight: 900; letter-spacing: 1px; font-size: 1.6rem; padding: 4px 8px; margin: -12px -12px 12px;
    text-transform: uppercase;
}
.paper.cengel .paper-title { background: var(--cengel-band); }
.paper-note { background: var(--kare-band); color: #fff; text-align: center; font-weight: 600; padding: 6px 10px; margin: 12px -12px; }
.active-clue {
    background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px;
    min-height: 40px; font-weight: 600;
}

.board-scroll { overflow-x: auto; padding-bottom: 4px; }
.kare-wrap { --cell-size: clamp(26px, calc((100vw - 120px) / 11), 46px); display: grid; justify-content: center; }
.kare-board { display: grid; grid-template-columns: 24px repeat(var(--cols), var(--cell-size)); }
.kare-num { display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; color: #222; }
.cell {
    position: relative; width: var(--cell-size); height: var(--cell-size);
    border: 1px solid #333; margin: 0 -1px -1px 0; background: var(--cell);
}
.cell.black { background: var(--cell-black); }
.cell.empty { background: var(--cell-empty); }
.cell input {
    width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background: transparent;
    text-align: center; text-transform: uppercase; font-weight: 700; color: var(--cell-ink);
    font-size: calc(var(--cell-size) * .5); caret-color: transparent; cursor: pointer; border-radius: 0;
}
.cell input:focus { outline: none; }
.cell.in-word { background: var(--hl-word); }
.cell.current { background: var(--hl-cell); }
.cell.wrong input { color: var(--bad); }
.cell.wrong { box-shadow: inset 0 0 0 2px var(--bad); }
.cell.solved input { color: #166534; }

.cengel-wrap { --cell-size: clamp(46px, calc((100vw - 64px) / 10), 76px); display: grid; justify-content: center; min-width: max-content; }
.cengel-board { display: grid; grid-template-columns: repeat(var(--cols), var(--cell-size)); }
.cell.clue { background: var(--clue-cell); color: var(--clue-ink); display: flex; flex-direction: column; cursor: pointer; }
.clue-part {
    flex: 1; display: flex; align-items: center; justify-content: center; text-align: center;
    font-size: clamp(9px, calc(var(--cell-size) * .19), 14px); line-height: 1.05; padding: 2px 6px 2px 3px;
    word-break: break-word; hyphens: auto; font-family: Georgia, "Times New Roman", serif; position: relative;
}
.clue-part + .clue-part { border-top: 1px solid #555; }
.clue-part.on { background: var(--hl-cell); }
/* Gazetedeki gibi: sağa ok hücrenin sağ kenarında, aşağı ok alt kenarında */
.clue-part .arr { position: absolute; color: var(--arrow); font-size: 15px; line-height: 1; font-family: system-ui, sans-serif; z-index: 1; }
.clue-part .arr.A { right: -6px; top: 50%; transform: translateY(-50%); }
.clue-part .arr.D { bottom: -9px; left: 50%; transform: translateX(-50%); }
.cell.clue + .cell, .cengel-board .cell { overflow: visible; }

.clues-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 4px; color: #111; }
@media (max-width: 560px) { .clues-cols { grid-template-columns: 1fr; } }
.clues-cols h4 { font-weight: 900; text-transform: uppercase; margin-bottom: 6px; }
.clues-cols ol { list-style: none; margin: 0; padding: 0; }
.clues-cols li { padding: 3px 6px; border-radius: 6px; cursor: pointer; font-size: 1.02rem; }
.clues-cols li:hover { background: #f1efe6; }
.clues-cols li.on { background: var(--hl-word); }
.clues-cols li.done { color: #6b7280; text-decoration: line-through; }
.clues-cols li b { margin-right: 4px; }

.bank { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; color: #111; }
.bank h5 { margin: 0 0 4px; background: var(--cengel-band); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: .85rem; }
.bank div { font-size: .82rem; letter-spacing: .5px; line-height: 1.4; }
.bank .bank-word.used { text-decoration: line-through; color: #9ca3af; }
.puzzle-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.puzzle-status { text-align: center; margin-top: 10px; font-weight: 700; min-height: 1.5em; }

/* ---------- Kalıplar ---------- */
.phrase-list { display: grid; gap: 8px; }
.phrase {
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.phrase summary {
    list-style: none; cursor: pointer; padding: 10px 14px; display: flex; gap: 10px; align-items: baseline;
}
.phrase summary::-webkit-details-marker { display: none; }
.phrase .ord { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.2em; }
.phrase .en { font-weight: 700; }
.phrase .tr { color: var(--muted); }
.phrase-body { padding: 0 14px 12px; }
.example { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 10px; align-items: start; padding: 8px 0; border-top: 1px dashed var(--border); }
.kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; background: var(--primary-soft); color: var(--primary); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.example .tr { display: block; font-size: .9rem; }
.quiz-opt {
    display: block; width: 100%; text-align: left; padding: 10px 14px; margin-top: 8px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer;
}
.quiz-opt:hover:not(:disabled) { background: var(--surface-2); }
.quiz-opt.right { background: var(--good-soft); border-color: var(--good); }
.quiz-opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.quiz-prompt { font-size: 1.1rem; font-weight: 700; margin: 6px 0; }

/* ---------- Kelime kartı ---------- */
.flash {
    text-align: center; padding: 30px 16px; border-radius: var(--radius);
    background: linear-gradient(135deg, var(--primary-soft), var(--surface-2));
}
.flash .front { font-size: 2rem; font-weight: 800; }
.flash .back { font-size: 1.2rem; margin-top: 10px; min-height: 1.8em; }
.flash .dir { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.box-dots { display: inline-flex; gap: 3px; margin-top: 8px; }
.box-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.box-dots i.on { background: var(--good); }

/* ---------- Telaffuz ---------- */
.voice-target { font-size: 1.35rem; font-weight: 700; color: var(--accent); text-align: center; margin: 12px 0 4px; }
.voice-tr { text-align: center; color: var(--muted); }
.mic {
    width: 76px; height: 76px; border-radius: 50%; border: 0; margin: 16px auto 8px; display: flex;
    align-items: center; justify-content: center; font-size: 1.9rem; cursor: pointer;
    background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(124, 58, 237, .3);
}
.mic.listening { background: var(--bad); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }
.diff { text-align: center; font-size: 1.1rem; margin-top: 8px; }
.diff .ok { color: var(--good); font-weight: 700; }
.diff .miss { color: var(--bad); text-decoration: underline wavy; }
.accuracy { text-align: center; font-weight: 800; font-size: 1.3rem; margin-top: 6px; }

/* ---------- Sözlük ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; color: var(--muted); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.tag { font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .5px; }
.add-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 720px) { .add-form { grid-template-columns: 1fr; } }

/* ---------- Dialog & toast ---------- */
dialog {
    border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(640px, calc(100vw - 32px));
    background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(10, 15, 25, .5); }
dialog form { padding: 18px; display: grid; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.ex-row { display: grid; grid-template-columns: 110px 1fr 1fr auto; gap: 6px; }
@media (max-width: 620px) { .ex-row { grid-template-columns: 1fr; } }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(420px, calc(100vw - 32px)); }
.toast {
    background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: rise .25s ease-out;
}
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.empty-state { text-align: center; color: var(--muted); padding: 24px; }
