:root {
    --bg:               #1a2e1f;
    --bg-elevated:      #243d2b;
    --surface:          #2d4a35;
    --accent:           #d4a04a;
    --accent-active:    #b88533;
    --text:             #e8e6dc;
    --text-muted:       #8fa994;
    --text-dim:         #5d7563;
    --border:           rgba(232, 230, 220, 0.08);
    --success:          #88b06a;
    --error:            #d97757;
    --warning:          #d4a04a;

    --s-1:  4px;
    --s-2:  8px;
    --s-3:  12px;
    --s-4:  16px;
    --s-5:  24px;
    --s-6:  32px;
    --s-7:  48px;

    --r-sm:   6px;
    --r-md:   12px;
    --r-lg:   20px;
    --r-full: 9999px;

    --fs-xs:   11px;
    --fs-sm:   13px;
    --fs-base: 15px;
    --fs-lg:   18px;
    --fs-xl:   22px;
    --fs-2xl:  28px;

    --nav-h:        64px;
    --touch:        44px;
    --safe-top:     env(safe-area-inset-top, 0px);
    --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: var(--fs-base);
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

.app {
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ====== Page system ====== */

.page {
    position: absolute;
    top:    var(--safe-top);
    left:   0;
    right:  0;
    bottom: calc(var(--nav-h) + var(--safe-bottom));
    padding: var(--s-5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page[hidden] { display: none; }

.page__title {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--s-5);
}

/* ====== Home page ====== */

.page--home {
    align-items: center;
    justify-content: center;
}

.home-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-5);
    width: 100%;
    max-width: 320px;
}

.gear {
    position: absolute;
    top:   calc(var(--safe-top) + var(--s-4));
    right: var(--s-4);
    width:  var(--touch);
    height: var(--touch);
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.gear:active { background: var(--surface); }

.action-primary {
    width:  220px;
    height: 220px;
    border-radius: var(--r-full);
    background: var(--accent);
    color: var(--bg);
    border: none;
    font-size: var(--fs-2xl);
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(212, 160, 74, 0.18);
    font-family: inherit;
    transition: transform 0.1s ease, background 0.15s ease;
}

.action-primary:active {
    background: var(--accent-active);
    transform: scale(0.96);
}

.action-primary:disabled {
    background: var(--text-dim);
    color: var(--bg);
    box-shadow: none;
}

.home-input {
    width: 100%;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: var(--fs-base);
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    line-height: 1.4;
    min-height: 48px;
}

.home-input::placeholder {
    color: var(--text-dim);
}

.home-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
}

.home-response {
    width: 100%;
    min-height: 84px;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
}

.home-response[data-state="error"] {
    color: var(--error);
}

/* ====== Cards ====== */

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-4);
    margin-bottom: var(--s-3);
}

.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
}

.card__label {
    font-size: var(--fs-base);
    color: var(--text);
    font-weight: 500;
}

.card__state {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}

.card__dot {
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    background: var(--text-dim);
    flex-shrink: 0;
}

.card__state[data-state="ok"]   .card__dot { background: var(--success); }
.card__state[data-state="err"]  .card__dot { background: var(--error); }
.card__state[data-state="warn"] .card__dot { background: var(--warning); }

.card__detail {
    margin-top: var(--s-2);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ====== Secondary action ====== */

.action-secondary {
    display: block;
    width: 100%;
    margin-top: var(--s-5);
    padding: var(--s-4);
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--r-md);
    font-size: var(--fs-base);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.action-secondary:active   { background: var(--accent-active); }
.action-secondary:disabled { background: var(--text-dim); color: var(--bg); }

.result {
    margin-top: var(--s-3);
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elevated);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* ====== Capability list ====== */

.cap-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    margin-top: var(--s-2);
}

.cap-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.cap-list__name {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: var(--fs-sm);
    color: var(--text);
    word-break: break-word;
}

.cap-list__badge {
    font-size: 10px;
    padding: var(--s-1) var(--s-2);
    border-radius: var(--r-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.cap-list__badge[data-state="approved"] { background: var(--success); color: var(--bg); }
.cap-list__badge[data-state="pending"]  { background: var(--warning); color: var(--bg); }
.cap-list__badge[data-state="denied"]   { background: var(--error);   color: var(--bg); }

/* ====== Options page ====== */

.muted {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    margin-bottom: var(--s-2);
}

.status-list {
    list-style: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-2) var(--s-3);
    margin-bottom: var(--s-3);
}

.status-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-sm);
}

.status-list__item:last-child { border-bottom: none; }

.status-list__label { color: var(--text); }

.status-list__value {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    color: var(--text-muted);
    font-size: var(--fs-xs);
}

.status-list__dot {
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    background: var(--text-dim);
    flex-shrink: 0;
}

.status-list__value[data-state="ok"]   .status-list__dot { background: var(--success); }
.status-list__value[data-state="err"]  .status-list__dot { background: var(--error); }
.status-list__value[data-state="warn"] .status-list__dot { background: var(--warning); }

.debug {
    flex: 1 1 auto;
    min-height: 80px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-3);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    -webkit-overflow-scrolling: touch;
}

.debug--compact {
    flex: 0 0 auto;
    max-height: 25vh;
    margin-bottom: var(--s-3);
}

/* ====== Bottom slider nav ====== */

.nav {
    position: absolute;
    left:   0;
    right:  0;
    bottom: 0;
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav::-webkit-scrollbar { display: none; }

.nav__item {
    flex: 1 0 auto;
    min-width: 96px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    cursor: pointer;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    position: relative;
    transition: color 0.15s ease;
}

.nav__item.active { color: var(--accent); }

.nav__item.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left:  30%;
    right: 30%;
    height: 3px;
    background: var(--accent);
    border-radius: var(--r-full) var(--r-full) 0 0;
}

.nav__item:active { color: var(--text); }
