/* ============================================================
   Pocket GBA — design tokens, reset, primitives.
   Palette & shapes follow the GBA Player design spec.
   ============================================================ */

:root {
    color-scheme: dark;

    /* palette (design spec) */
    --bg: #110f1f;
    --bg-deep: #07060f;
    --s1: #1b1830;
    --s2: #27233f;
    --s3: #322c52;
    --tx: #efecff;
    --mu: #8f89b5;
    --ac: #8b7cff;
    --ac-ink: #120d2e;
    --pk: #ff5c8a;
    --hi: #ffd166;
    --er: #ff4d5e;
    --lcd: #b9d79b;
    --line: rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.14);

    /* shape */
    --r-s: 10px;
    --r-m: 14px;
    --r-l: 20px;
    --r-xl: 24px;
    --shadow-1: 0 2px 12px rgba(0, 0, 0, 0.28);
    --shadow-2: 0 14px 40px rgba(0, 0, 0, 0.5);

    /* metrics */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --font: 'Noto Sans Thai', 'Sarabun', -apple-system, BlinkMacSystemFont,
        'SF Pro Text', 'Segoe UI', Roboto, 'Thonburi', 'Leelawadee UI', sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

/* ----------------------------- reset ----------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg-deep);
    color: var(--tx);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
}

body.no-scroll {
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    touch-action: manipulation;
}

h1, h2, h3, h4, p {
    margin: 0;
}

img {
    display: block;
    max-width: 100%;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--ac);
    outline-offset: 2px;
    border-radius: 6px;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--s2) transparent;
}
*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
*::-webkit-scrollbar-thumb {
    background: var(--s2);
    border-radius: 6px;
}

/* ----------------------------- type ----------------------------- */

.h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.h2 {
    font-size: 15px;
    font-weight: 700;
}

.sub {
    color: var(--mu);
}

.note {
    color: var(--mu);
    font-size: 12px;
    line-height: 1.55;
}

.muted {
    color: var(--mu);
}

.dim {
    color: var(--mu);
    opacity: 0.75;
}

.small {
    font-size: 12px;
}

.mono {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

/* ----------------------------- buttons ----------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--s2);
    border: 0;
    border-radius: var(--r-s);
    padding: 8px 12px;
    min-height: 36px;
    font-weight: 600;
    color: var(--tx);
    transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.45;
    pointer-events: none;
}

.btn.p {
    background: var(--ac);
    color: var(--ac-ink);
    font-weight: 700;
}

.btn.d {
    background: #3a1b2b;
    color: #ff9aa8;
}

.btn.ghost {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--mu);
}

.btn.block {
    width: 100%;
}

.btn.big {
    min-height: 46px;
    padding: 0 18px;
    font-size: 15px;
    border-radius: 12px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: var(--mu);
    background: transparent;
    transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.icon-btn:hover {
    background: var(--s2);
    color: var(--tx);
}

.icon-btn:active {
    transform: scale(0.92);
}

/* ----------------------------- chips ----------------------------- */

.chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 6px 0;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: 99px;
    background: var(--s2);
    border: 0;
    color: var(--tx);
    font-size: 12px;
    min-height: 34px;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.chip:active {
    transform: scale(0.96);
}

.chip.on {
    background: var(--ac);
    color: var(--ac-ink);
    font-weight: 700;
}

.chip.d {
    background: #3a1b2b;
    color: #ff9aa8;
}

.chip.warn {
    background: #3a3118;
    color: var(--hi);
}

/* ----------------------------- toggles & rows ----------------------------- */

.tg {
    width: 46px;
    height: 26px;
    border-radius: 99px;
    background: #4a4478;
    position: relative;
    border: 0;
    flex: none;
    transition: background 0.18s ease;
}

.tg::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: left 0.18s ease;
}

.tg.on {
    background: var(--ac);
}

.tg.on::after {
    left: 23px;
}

.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 13px 0;
    border-bottom: 1px solid var(--line);
}

.row:last-child {
    border-bottom: none;
}

.row.v {
    display: block;
}

.row .lbl {
    min-width: 0;
}

.row .lbl .name {
    font-size: 14px;
    font-weight: 600;
}

.row .lbl .desc {
    margin-top: 2px;
}

/* ----------------------------- range slider ----------------------------- */

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 32px;
    background: transparent;
    accent-color: var(--ac);
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 5px;
    border-radius: 99px;
    background: var(--s2);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -7.5px;
    border-radius: 50%;
    background: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-moz-range-track {
    height: 5px;
    border-radius: 99px;
    background: var(--s2);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: none;
}

/* ----------------------------- text inputs ----------------------------- */

.text-input,
.select {
    appearance: none;
    -webkit-appearance: none;
    min-height: 40px;
    padding: 0 12px;
    border-radius: var(--r-s);
    background: var(--s2);
    border: 1px solid var(--line-strong);
    color: var(--tx);
    user-select: text;
    -webkit-user-select: text;
}

.select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238f89b5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

/* ----------------------------- toasts ----------------------------- */

.toast-host {
    position: fixed;
    left: 50%;
    bottom: 90px;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: max-content;
    max-width: 86vw;
}

.toast {
    background: rgba(0, 0, 0, 0.82);
    color: var(--tx);
    padding: 8px 16px;
    border-radius: 99px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: var(--shadow-2);
}

.toast.show {
    opacity: 1;
}

/* ----------------------------- sheets & dialogs ----------------------------- */

.sheet-wrap {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 2, 8, 0.66);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.sheet-panel {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 88%;
    display: flex;
    flex-direction: column;
    background: var(--s1);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.55);
    transform: translateY(22px);
    opacity: 0;
    transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.25, 1), opacity 0.2s ease;
    padding-bottom: var(--safe-bottom);
}

.sheet-wrap[data-open="1"] .sheet-backdrop {
    opacity: 1;
}

.sheet-wrap[data-open="1"] .sheet-panel {
    transform: translateY(0);
    opacity: 1;
}

.sheet-grabber {
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: #4a4478;
    margin: 8px auto;
    flex: none;
    cursor: pointer;
}

.sheet-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 16px 10px;
}

.sheet-title {
    flex: 1;
    font-size: 17px;
    font-weight: 800;
}

.sheet-body {
    overflow-y: auto;
    padding: 0 16px 18px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

@media (min-width: 640px) {
    .sheet-wrap {
        align-items: center;
        padding: 20px;
    }
    .sheet-panel {
        border-radius: var(--r-xl);
        transform: translateY(12px) scale(0.98);
    }
    .sheet-wrap[data-open="1"] .sheet-panel {
        transform: translateY(0) scale(1);
    }
    .sheet-grabber {
        display: none;
    }
    .sheet-head {
        padding-top: 16px;
    }
}

/* centered pause-style modal */
.modal-wrap {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.7);
    display: grid;
    place-items: center;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.modal-wrap[data-open="1"] {
    opacity: 1;
}

.modal {
    width: min(300px, 82%);
    background: var(--s1);
    border-radius: 22px;
    padding: 10px;
    transform: scale(0.95);
    transition: transform 0.18s ease;
}

.modal-wrap[data-open="1"] .modal {
    transform: scale(1);
}

.modal-title {
    padding: 8px 14px 4px;
    font-size: 13px;
    font-weight: 700;
    color: var(--mu);
}

.modal button {
    display: block;
    width: 100%;
    text-align: left;
    background: 0;
    border: 0;
    font-size: 15px;
    padding: 12px 14px;
    border-radius: 12px;
    min-height: 44px;
    color: var(--tx);
}

.modal button:active {
    background: var(--s2);
}

.modal button.d {
    color: var(--er);
}

/* confirm */
.confirm-message {
    color: var(--mu);
    padding: 4px 2px 16px;
    line-height: 1.6;
}

.confirm-actions {
    display: flex;
    gap: 10px;
}

.confirm-actions .btn {
    flex: 1;
    min-height: 42px;
}

/* spinner */
.spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--ac);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.divider {
    height: 1px;
    background: var(--line);
    margin: 14px 0;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ----------------------------- ui.js compatibility ----------------------------- */

#toast-host {
    position: fixed;
    left: 50%;
    bottom: 90px;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: max-content;
    max-width: 86vw;
}

#toast-host .toast {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ac);
    flex: none;
}

.toast-error .toast-dot {
    background: var(--er);
}

.toast-warn .toast-dot {
    background: var(--hi);
}

.btn-primary {
    background: var(--ac);
    color: var(--ac-ink);
    font-weight: 700;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--mu);
}

.btn-danger {
    background: #3a1b2b;
    color: #ff9aa8;
}

.sheet-head .sheet-grabber {
    flex-basis: 100%;
    order: -1;
    margin: 0 auto 6px;
}

.sheet-grabber.floating {
    margin: 8px auto 2px;
}

.sheet-narrow {
    max-width: 420px;
}

.sheet-close {
    flex: none;
}

.confirm-content {
    padding-bottom: 6px;
}

/* picker list (state/choice sheets) */
.picker-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 4px 0;
}

.picker-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    padding: 10px 8px;
    border-radius: 12px;
    background: transparent;
    border: 0;
    color: var(--tx);
}

.picker-row:active {
    background: var(--s2);
}

.picker-row.disabled {
    opacity: 0.45;
}

.picker-thumb {
    width: 72px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--s2);
    flex: none;
}

.picker-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.picker-thumb.empty {
    background: var(--s1);
    border: 1px solid var(--line);
}

.picker-main {
    flex: 1;
    min-width: 0;
}

.picker-title {
    font-weight: 700;
    font-size: 13.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.picker-sub {
    color: var(--mu);
    font-size: 11.5px;
}

.picker-meta {
    color: var(--mu);
    font-size: 11.5px;
    flex: none;
}

.picker-hint {
    color: var(--mu);
    font-size: 12px;
    margin: 8px 4px 2px;
}

/* spinner overlay */
.spinner-overlay {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: grid;
    place-items: center;
    background: rgba(7, 6, 15, 0.55);
}

.spinner-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: var(--s1);
    padding: 22px 30px;
    border-radius: var(--r-l);
    box-shadow: var(--shadow-2);
}

.spinner-label {
    color: var(--mu);
    font-size: 12.5px;
}
