/* Kelime Bulma Makinesi: sade, düşük kontrastlı yüzeyler, tek vurgu rengi, sistem fontu */

:root,
[data-theme="light"] {
    --bg: #fafaf9;
    --surface: #ffffff;
    --subtle: #f3f3f1;
    --border: #e4e4e0;
    --text: #1c1c1a;
    --muted: #6b6b66;
    --faint: #a3a39d;
    --accent: #0f766e;
    --accent-soft: #e3f1ef;
    --on-accent: #ffffff;
    --joker: #c2410c;
    --star: #b45309;
    --danger: #b91c1c;
    --backdrop: rgba(20, 20, 18, 0.4);
}

[data-theme="dark"] {
    --bg: #121212;
    --surface: #1b1b1a;
    --subtle: #232322;
    --border: #2e2e2c;
    --text: #ececea;
    --muted: #a3a39d;
    --faint: #6b6b66;
    --accent: #5eead4;
    --accent-soft: #17302d;
    --on-accent: #06201c;
    --joker: #fb923c;
    --star: #fbbf24;
    --danger: #f87171;
    --backdrop: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }

body.kb-body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    padding:
        calc(16px + env(safe-area-inset-top))
        calc(18px + env(safe-area-inset-right))
        calc(40px + env(safe-area-inset-bottom))
        calc(18px + env(safe-area-inset-left));
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
}

body.kb-lock { overflow: hidden; }

button { font: inherit; color: inherit; -webkit-touch-callout: none; }

.kb-app { width: min(100%, 560px); margin: 0 auto; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- başlık ---------- */

.kb-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.kb-title-link { color: inherit; text-decoration: none; }
.kb-title { margin: 0; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }

.kb-pill-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.kb-pill-btn:hover { color: var(--text); }

/* ---------- form ---------- */

.kb-label { display: block; margin-bottom: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }

.kb-letters-row { display: flex; gap: 8px; align-items: stretch; }

.kb-letters {
    flex: 1 1 auto;
    min-width: 0;
    height: 54px;
    padding: 0 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    font: inherit;
    font-size: 1.35rem;           /* 16px üstü: iOS yakınlaştırmaz */
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    -webkit-appearance: none;
    appearance: none;
}
.kb-letters::placeholder, .kb-input::placeholder { color: var(--faint); font-weight: 400; letter-spacing: 0.02em; }
.kb-letters:focus, .kb-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.kb-icon-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.kb-icon-btn:hover { color: var(--text); background: var(--subtle); }
.kb-icon-btn:active { background: var(--subtle); }
.kb-letters-row .kb-icon-btn { height: 54px; }
.kb-joker { color: var(--joker); font-size: 1.35rem; font-weight: 600; }
.kb-joker:hover { color: var(--joker); }

.kb-hint { margin: 8px 0 20px; color: var(--muted); font-size: 0.85rem; min-height: 1.3em; }
.kb-hint b { color: var(--joker); font-weight: 600; }

.kb-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
.kb-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kb-field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }

.kb-input {
    width: 100%;
    height: 46px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    -webkit-appearance: none;
    appearance: none;
}

.kb-btn {
    display: block;
    width: 100%;
    min-height: 50px;
    padding: 0 20px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
.kb-btn:hover:not(:disabled) { filter: brightness(0.94); }
.kb-btn:active:not(:disabled) { filter: brightness(0.88); }
.kb-btn:disabled { opacity: 0.5; cursor: default; }
.kb-btn-small { width: auto; min-height: 40px; padding: 0 18px; font-size: 0.92rem; }

.kb-msg { margin: 16px 0 0; padding: 12px 14px; border-radius: 10px; background: var(--subtle); color: var(--muted); font-size: 0.92rem; }
.kb-msg[hidden] { display: none; }
.kb-msg.kb-err { color: var(--danger); }
.kb-msg button { background: none; border: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

/* ---------- sonuçlar ---------- */

.kb-results { margin-top: 28px; }
.kb-results[hidden] { display: none; }

.kb-summary { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 14px; margin-bottom: 8px; }
.kb-summary strong { font-size: 1.05rem; font-weight: 600; }
.kb-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 0.78rem; color: var(--muted); }
.kb-lg { font-style: normal; }
.kb-lg-j { color: var(--joker); }
.kb-lg-f { color: var(--accent); }
.kb-lg-s { color: var(--star); }

.kb-lens {
    position: sticky;
    top: env(safe-area-inset-top);
    z-index: 5;
    display: flex;
    gap: 6px;
    margin: 0 -18px 4px;
    padding: 8px 18px;
    overflow-x: auto;
    background: var(--bg);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.kb-lens::-webkit-scrollbar { display: none; }
.kb-lens[hidden] { display: none; }
.kb-lens button {
    flex: 0 0 auto;
    min-width: 40px;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}
.kb-lens button[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.kb-group { border-top: 1px solid var(--border); }
.kb-group[hidden] { display: none; }

.kb-ghead {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 10px 0;
    border: none;
    background: none;
    text-align: left;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
}
.kb-ghead .kb-gn { margin-left: auto; color: var(--muted); font-size: 0.85rem; font-weight: 500; }
.kb-ghead svg { flex: 0 0 auto; color: var(--faint); transition: transform 0.15s ease; }
.kb-group.kb-closed .kb-ghead svg { transform: rotate(-90deg); }
.kb-group.kb-closed .kb-words, .kb-group.kb-closed .kb-more { display: none; }

.kb-words { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 0 16px; }

.kb-word {
    display: inline-flex;
    align-items: baseline;
    min-height: 44px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.kb-word:hover { border-color: var(--faint); }
.kb-word:active { background: var(--subtle); }
.kb-word .kb-l { display: inline-block; letter-spacing: 0.05em; font-kerning: none; font-feature-settings: 'kern' 0, 'liga' 0; }
.kb-word .kb-j { color: var(--joker); }
.kb-word .kb-f { color: var(--accent); }
.kb-word .kb-sc { margin-left: 8px; font-size: 0.7rem; font-weight: 500; letter-spacing: 0; color: var(--faint); }
.kb-word .kb-st { margin-left: 4px; color: var(--star); font-size: 0.75rem; letter-spacing: 0; }

.kb-more[hidden] { display: none; }
.kb-more { display: block; width: 100%; margin: 0 0 16px; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }
.kb-more:hover { background: var(--subtle); }

/* ---------- yardım / kurulum / alt bilgi ---------- */

.kb-help { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 4px; }
.kb-help summary { display: flex; align-items: center; justify-content: space-between; min-height: 48px; cursor: pointer; list-style: none; font-weight: 600; font-size: 0.95rem; }
.kb-help summary::-webkit-details-marker { display: none; }
.kb-help summary::after { content: '+'; color: var(--muted); font-size: 1.3rem; font-weight: 400; }
.kb-help[open] summary::after { content: '−'; }
.kb-help ol { margin: 0 0 12px; padding-left: 20px; color: var(--muted); font-size: 0.92rem; }
.kb-help li { margin-bottom: 4px; }
.kb-help p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }
.kb-help b { color: var(--text); font-weight: 600; }

.kb-install { position: relative; display: flex; align-items: center; gap: 12px; margin-top: 18px; padding: 14px 52px 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.kb-install[hidden] { display: none; }
.kb-install-text { flex: 1 1 auto; min-width: 0; }
.kb-install h2 { margin: 0 0 2px; font-size: 0.95rem; font-weight: 600; }
.kb-install-text p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.kb-install-text .kb-share { display: inline-block; vertical-align: -4px; }
.kb-install-close { position: absolute; top: 6px; right: 6px; width: 36px; min-height: 36px; border: none; }

.kb-footer { margin-top: 28px; color: var(--faint); font-size: 0.78rem; }
.kb-footer p { margin: 0 0 6px; }
.kb-offline { font-weight: 500; color: var(--muted); }
.kb-offline.kb-ready { color: var(--accent); }

/* ---------- alttan açılan anlam sayfası ---------- */

.kb-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.kb-overlay[hidden] { display: none; }
.kb-backdrop { position: absolute; inset: 0; background: var(--backdrop); }

.kb-sheet {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(100%, 560px);
    max-height: 86vh;
    max-height: 86dvh;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    animation: kbUp 0.22s ease-out;
    overscroll-behavior: contain;
}
.kb-sheet.kb-dragging { animation: none; transition: none; }
@keyframes kbUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.kb-sheet-top { flex: 0 0 auto; padding: 8px 20px 0; touch-action: none; }
.kb-grab { display: block; width: 36px; height: 4px; margin: 0 auto 8px; border-radius: 2px; background: var(--border); }
.kb-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.kb-sheet-title { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; word-break: break-word; }

.kb-sheet-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px 20px calc(28px + env(safe-area-inset-bottom));
}

.kb-entry + .kb-entry { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.kb-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.kb-tag { padding: 2px 10px; border-radius: 999px; background: var(--subtle); color: var(--muted); font-size: 0.8rem; }
.kb-tag-o { background: var(--accent-soft); color: var(--accent); }
.kb-defs { margin: 0; padding-left: 22px; }
.kb-defs li { margin-bottom: 14px; padding-left: 4px; font-size: 1.02rem; line-height: 1.6; }
.kb-defs li::marker { color: var(--faint); font-weight: 500; }
.kb-lab { margin-right: 6px; color: var(--muted); font-size: 0.85rem; font-style: italic; }
.kb-ex { margin: 6px 0 0; color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.kb-rel { margin: 10px 0 0; font-size: 0.92rem; color: var(--muted); }
.kb-rel b { color: var(--text); font-weight: 600; }
.kb-empty { color: var(--muted); font-size: 0.95rem; }
.kb-empty button { background: none; border: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

@media (min-width: 700px) {
    body.kb-body { padding-top: 40px; }
    .kb-overlay { align-items: center; }
    .kb-sheet { border-radius: 16px; max-height: 80vh; }
}

@media (prefers-reduced-motion: reduce) {
    .kb-sheet { animation: none; }
    .kb-ghead svg { transition: none; }
}
