:root {
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --primary-text: #ffffff;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --bad: #dc2626;
    --bad-soft: #fee2e2;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --radius: 14px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --primary-soft: #1e3a8a;
    --ok-soft: #14532d;
    --bad-soft: #7f1d1d;
    --warn: #fbbf24;
    --warn-soft: #422006;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 0 0 6px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
p { margin: 0 0 12px; }
code { font-size: .95em; background: var(--bg); padding: 1px 6px; border-radius: 6px; }
.hidden { display: none !important; }

/* Telefonda tarayıcıdan açıldığında yalnızca tanıtım ekranı görünür */
html.gated .app-only { display: none !important; }
html:not(.gated) .gate-only { display: none !important; }

/* ---- Üst çubuk ve sekmeler ---- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand img { border-radius: 7px; }
.user { display: flex; align-items: center; gap: 12px; font-size: .9rem; min-width: 0; }
.user a { color: var(--muted); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user form { margin: 0; }

.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}
.tabs a {
    flex: none;
    padding: 6px 14px;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    font-size: .95rem;
}
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
:root[data-theme="dark"] .tabs a.active { color: #bfdbfe; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px);
}
.login, .narrow { max-width: 440px; margin: 0 auto; }
.login { padding-top: 4vh; }
.login-card { padding: 28px 24px 20px; }
.login-card .app-icon { margin: 0 0 12px; }
.login-card h1 { margin: 0 0 4px; }
.login-card .lead { margin: 0 0 20px; }
.login-card .stack { gap: 14px; }
.login-card .btn.primary { margin-top: 4px; }
.login-card .foot { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---- Kartlar ve düzen ---- */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}
.card.error { border-color: var(--bad); color: var(--bad); }
.card.success { border-color: var(--ok); }
.highlight-card { border-color: var(--primary); }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.app-icon { border-radius: 16px; margin: 4px 0 10px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: .9rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

.row { display: flex; gap: 10px; margin: 12px 0; align-items: center; }
.row > .btn, .row > label.btn { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > * { flex: none; }
.row form { margin: 0; }
.row input { flex: 1; }

.grid-2 { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; white-space: pre-line; }
.alert.success { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--bad-soft); color: var(--bad); }
:root[data-theme="dark"] .alert.success, :root[data-theme="dark"] .alert.error { color: var(--text); }
.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: .92rem; }
.note { font-size: .9rem; background: var(--bg); border-radius: 10px; padding: 10px 12px; text-align: left; }
.note.success { color: var(--ok); }

/* ---- Butonlar ve formlar ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .88rem; border-radius: 10px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label, label.quick { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; font-weight: 600; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: .9rem; }
.check-row { flex-direction: row !important; align-items: center; gap: 10px !important; font-weight: 400 !important; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-weight: 400 !important; flex-direction: row !important; }
.search { max-width: 260px; }

/* ---- Listeler ---- */

.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}
.list li:first-child { border-top: 0; }
.list li > a, .list li > span:first-child { display: flex; flex-direction: column; min-width: 0; color: var(--text); text-decoration: none; }
.list li form { margin: 0; }
.list.compact li { padding: 7px 0; }
.list .actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.list li .check { color: var(--ok); font-weight: 700; visibility: hidden; }
.list li.done .check { visibility: visible; }
.list li.done { color: var(--muted); }
.list li[hidden] { display: none; }

.badge { flex: none; display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: .8rem; font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.score { font-size: 1.3rem; font-weight: 700; color: var(--primary); }

.features { padding-left: 20px; margin: 0 0 10px; }
.features li { margin-bottom: 8px; }

details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 10px; }
.class-group[hidden] { display: none; }

/* ---- İstatistik, tablo, karşılaştırma ---- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; text-align: center; margin: 10px 0; }
.stats div { background: var(--bg); border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; }
.stats span { font-size: .75rem; color: var(--muted); }
.stats b { font-size: 1.2rem; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
tr.absent td { color: var(--muted); }

.compare { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.compare-head { display: none; }
.compare-row {
    display: grid;
    grid-template-columns: 2.2em 1fr 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--bg);
    font-size: .92rem;
}
.compare-row span:first-child { color: var(--muted); }
.compare-row span:nth-child(3) { color: var(--muted); }
.compare-row span:nth-child(3)::before { content: "→ "; }
.compare-row.ok { background: var(--ok-soft); color: var(--text); }
.compare-row.bad { background: var(--bad-soft); color: var(--text); }
.compare-row .mark { font-weight: 700; font-size: .85rem; }
.compare-row.ok .mark { color: var(--ok); }
.compare-row.bad .mark { color: var(--bad); }
.compare-row.blank .mark { color: var(--muted); font-weight: 400; }
:root[data-theme="dark"] .compare-row.ok .mark, :root[data-theme="dark"] .compare-row.bad .mark { color: var(--text); }

/* ---- Cevap anahtarı ---- */

.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 18px; margin-top: 12px; }
.key-row { display: flex; align-items: center; gap: 4px; }
.key-row > span { width: 2.2em; text-align: right; color: var(--muted); font-size: .9rem; margin-right: 4px; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.opt span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    font-size: .85rem;
    font-weight: 600;
    color: var(--muted);
}
.opt input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.opt input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0 calc(env(safe-area-inset-bottom) + 12px); background: linear-gradient(transparent, var(--bg) 35%); }
.sticky-save .btn { width: 100%; }

/* ---- Optik okutma ---- */

.preview canvas { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ok); margin: 0 2px 0 8px; }
.dot.multi { border-color: var(--bad); }
.answer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; margin-top: 10px; }
.answer-grid div { display: flex; justify-content: space-between; padding: 4px 8px; border-radius: 8px; background: var(--bg); font-size: .9rem; }
.answer-grid span { color: var(--muted); }
.answer-grid .blank b { color: var(--muted); }
.answer-grid .multi { color: var(--bad); }

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    vertical-align: -3px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Tanıtım / kurulum ekranı ---- */

#install-btn { width: 100%; margin: 8px 0 4px; }
.steps { text-align: left; margin-top: 12px; }
.steps ol { padding-left: 22px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }
.key { vertical-align: -3px; color: var(--primary); }
.steps.highlight { animation: pulse 1.2s ease 2; border-radius: 10px; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 transparent; }
    50% { box-shadow: 0 0 0 4px var(--primary); }
}
#install-hint { margin-top: 8px; color: var(--primary); font-weight: 600; }

.link-card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    color: var(--text);
    text-decoration: none;
}

/* ---- Sınav formu ---- */

.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented label { position: relative; flex-direction: row !important; font-weight: 600 !important; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 6px 14px; border-radius: 9px; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }
/* Tam genişlik: sekmeler eşit bölünür */
.segmented.full { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; width: 100%; }
.segmented.full label { display: block !important; }
.segmented.full span { text-align: center; padding: 9px 12px; }
.segmented.full.three { grid-template-columns: 1fr 1fr 1fr; }
fieldset[hidden], div[hidden], .booklet-pane[hidden] { display: none !important; }
textarea.plain { font-family: inherit; font-size: 1rem; }
.sections { display: flex; flex-direction: column; gap: 8px; }
.section-row { display: grid; grid-template-columns: 1fr 90px auto; gap: 8px; align-items: center; }
.section-row input[type=number] { text-align: center; }
.error-note { background: var(--bad-soft); color: var(--bad); }
:root[data-theme="dark"] .error-note { color: var(--text); }
.note { white-space: pre-line; }
.wide-form { max-width: 560px; }
.description { white-space: pre-line; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.badge.kind { background: var(--primary-soft); color: var(--primary); vertical-align: 2px; }
:root[data-theme="dark"] .badge.kind { color: #bfdbfe; }
.badge.ok-badge { background: var(--ok-soft); color: var(--ok); }
.block { display: block; }
.list li.stacked { flex-direction: column; align-items: stretch; }
.list-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.list li.stacked .description { margin: 8px 0 0; }
.score-input { width: 90px !important; text-align: center; }
.card.warn-card { border-color: var(--warn); }
h3 { font-size: .95rem; margin: 14px 0 6px; color: var(--muted); }

.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.legend span { background: var(--bg); border-radius: 8px; padding: 4px 10px; font-size: .9rem; }
.score-input.invalid { outline: 2px solid var(--bad); }
.badge.status { background: var(--warn-soft); color: var(--warn); }

/* Yazılı sınav notları: 5 Pekiyi ... 1 Geçmez; durumlar: Kopya siyah, Girmedi mavi, Muaf yeşil */
.grade { display: inline-block; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: .92rem; white-space: nowrap; }
.score .grade { font-size: 1rem; }
.stats .grade { font-size: 1.05rem; }
.grade.g5 { background: #15803d; color: #fff; }
.grade.g4 { background: #bbf7d0; color: #14532d; }
.grade.g3 { background: #fef08a; color: #713f12; }
.grade.g2 { background: #fed7aa; color: #7c2d12; }
.grade.g1 { background: #dc2626; color: #fff; }
.grade.st-kopya { background: #111827; color: #fff; }
.grade.st-girmedi { background: #2563eb; color: #fff; }
.grade.st-muaf { background: #16a34a; color: #fff; }
:root[data-theme="dark"] .grade.g4 { background: #166534; color: #dcfce7; }
:root[data-theme="dark"] .grade.g3 { background: #854d0e; color: #fef9c3; }
:root[data-theme="dark"] .grade.g2 { background: #9a3412; color: #ffedd5; }
:root[data-theme="dark"] .grade.st-kopya { background: #000; color: #fff; box-shadow: inset 0 0 0 1px #475569; }
/* Puan giriş kutusu da girilen değere göre renklenir */
.score-input.g5, .score-input.g4, .score-input.g3, .score-input.g2, .score-input.g1,
.score-input.st-kopya, .score-input.st-girmedi, .score-input.st-muaf { font-weight: 700 !important; border-color: transparent !important; }
.score-input.g5 { background: #15803d !important; color: #fff !important; }
.score-input.g4 { background: #bbf7d0 !important; color: #14532d !important; }
.score-input.g3 { background: #fef08a !important; color: #713f12 !important; }
.score-input.g2 { background: #fed7aa !important; color: #7c2d12 !important; }
.score-input.g1 { background: #dc2626 !important; color: #fff !important; }
.score-input.st-kopya { background: #111827 !important; color: #fff !important; }
.score-input.st-girmedi { background: #2563eb !important; color: #fff !important; }
.score-input.st-muaf { background: #16a34a !important; color: #fff !important; }
:root[data-theme="dark"] .score-input.g4 { background: #166534 !important; color: #dcfce7 !important; }
:root[data-theme="dark"] .score-input.g3 { background: #854d0e !important; color: #fef9c3 !important; }
:root[data-theme="dark"] .score-input.g2 { background: #9a3412 !important; color: #ffedd5 !important; }
:root[data-theme="dark"] .score-input.st-kopya { background: #000 !important; box-shadow: inset 0 0 0 1px #475569; }
.legend .grade { font-size: .85rem; }
.stack.sub { padding-left: 28px; gap: 8px; }
.grid-2.tight { gap: 8px; }
@media (min-width: 480px) { .grid-2.tight { grid-template-columns: 1fr 1fr; } }

/* ---- Ayarlar: açma/kapama anahtarı ---- */

.switch-row { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 16px; font-weight: 400 !important; }
.switch-row b { font-size: 1rem; }
input.switch { appearance: none; -webkit-appearance: none; flex: none; width: 50px !important; height: 30px !important; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
input.switch:checked { background: var(--ok); }
input.switch:checked::after { transform: translateX(20px); }
input.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sub-options { gap: 10px !important; padding-left: 4px; transition: opacity .15s; }
.sub-options.disabled { opacity: .45; pointer-events: none; }
.badge.this-device { background: var(--ok-soft); color: var(--ok); vertical-align: 1px; }

/* ---- Optik düzenleyici ---- */

.editor-canvas { width: 100%; height: auto; display: block; border-radius: 8px; border: 1px solid var(--border); background: #fff; margin-bottom: 8px; }
.editor-layout { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
    .editor-layout { grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); align-items: start; }
    .editor-view { position: sticky; top: 110px; }
    .container:has(.editor-layout) { max-width: 1280px; }
}
.field-list { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; margin-bottom: 10px; }
.field-card { border: 1.5px solid var(--border); border-radius: 12px; padding: 10px; cursor: pointer; }
.field-card.selected { border-color: var(--bad); }
.field-card.weak:not(.selected) { border-color: var(--warn); }
.field-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.field-grid label { display: flex; flex-direction: column; gap: 2px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.field-grid input, .field-grid select { padding: 6px 8px !important; font-size: .9rem !important; }
.field-grid .span-2 { grid-column: 1 / -1; }
.field-card .row { margin: 8px 0 0; }

/* Oluşturulan hesap şifrelerini yazdırırken yalnızca o kart çıksın */
@media print {
    .topbar, .tabs, .card:not(.highlight-card), .grid-2, .btn, h1 { display: none !important; }
    body, .card { background: #fff; color: #000; border: 0; }
}
