/* =========================================
   Universal UI Baseline Integration
========================================= */
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;scroll-behavior:smooth;line-height:1.5}
body,h1,h2,h3,h4,h5,p,figure{margin:0}
button,input,select,textarea{font:inherit;font-size:100%;line-height:1.5;margin:0;color:inherit}
button,input{overflow:visible} button,select{text-transform:none}
button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}
img,svg{max-width:100%;display:block} a{color:inherit}

:root{
    color-scheme:light dark;
    --bg:#f5f6f8;--surface:#fff;--surface2:#fafbfc;--surface3:#f1f3f5;
    --text:#17191d;--muted:#69707c;--muted2:#9299a3;--border:#dfe3e8;--border2:#cbd1d9;
    --primary:#2563eb;--primary2:#1d4ed8;--primarySoft:#eef4ff;
    --ok:#16834b;--okSoft:#edf8f2;--warn:#a56516;--warnSoft:#fff7e8;--bad:#c43e3e;--badSoft:#fff0f0;
    --shadow:0 1px 2px rgba(20,25,35,.03),0 8px 24px rgba(20,25,35,.04);
    --control:44px;--buttonVisual:44px;
}

:root[data-theme="light"]{
    color-scheme:light;
    --bg:#f5f6f8;--surface:#ffffff;--surface2:#fafbfc;--surface3:#f1f3f5;
    --text:#17191d;--muted:#69707c;--muted2:#9299a3;--border:#dfe3e8;--border2:#cbd1d9;
    --primary:#2563eb;--primary2:#1d4ed8;--primarySoft:#eef4ff;
    --ok:#16834b;--okSoft:#edf8f2;--warn:#a56516;--warnSoft:#fff7e8;--bad:#c43e3e;--badSoft:#fff0f0;
    --shadow:0 1px 2px rgba(20,25,35,.03),0 8px 24px rgba(20,25,35,.04);
}
:root[data-theme="dark"]{
    color-scheme:dark;
    --bg:#17191e;--surface:#202329;--surface2:#1c1f24;--surface3:#282c33;
    --text:#eef1f5;--muted:#b3bac4;--muted2:#8f97a3;--border:#343941;--border2:#454b55;
    --primary:#7ea8ff;--primary2:#96b8ff;--primarySoft:#26344f;
    --ok:#5fca8a;--okSoft:#203329;--warn:#e1ac5a;--warnSoft:#362d20;--bad:#ef8181;--badSoft:#382426;
    --shadow:0 1px 2px rgba(0,0,0,.12),0 10px 28px rgba(0,0,0,.14);
}

body { 
    font-family: 'Inter', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif; 
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    -webkit-tap-highlight-color: transparent; 
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.btn {
    position: relative;
    min-height: var(--buttonVisual);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    border: 1px solid var(--border2);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.soft { background: var(--surface2); border-color: var(--border); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

@media(hover:hover){
    .btn:hover:not(:disabled) { border-color: var(--primary); }
    .btn.primary:hover:not(:disabled) { background: var(--primary2); }
    .btn.danger:hover:not(:disabled) { background: var(--bad); opacity: 0.9; border-color: var(--bad); }
}

.field { display: grid; gap: 6px; min-width: 0; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; }
.control {
    width: 100%;
    min-height: var(--control);
    padding: 0 12px;
    border: 1px solid var(--border2);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    outline: 0;
    transition: all 0.2s;
}
.control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

#app-root { width: 100%; display: flex; justify-content: center; align-items: center; flex: 1; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow);
    width: 100%;
    margin: 0 auto;
}

.btn-settings {
    position: absolute; top: 24px; right: 24px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border2); border-radius: 50%;
    color: var(--muted); transition: all 0.2s; box-shadow: var(--shadow); z-index: 20;
    display: grid; place-items: center; cursor: pointer;
}
.btn-settings:hover { background: var(--surface2); color: var(--primary); border-color: var(--primary); }

.text-center { text-align: center; }
.text-title { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.3; letter-spacing: -0.02em; margin-bottom: 8px;}
.text-muted { color: var(--muted); font-size: 14px; }
.link { font-weight: 600; color: var(--primary); transition: color 0.2s; font-size: 13px; text-decoration: none; cursor: pointer; border: none; background: transparent; padding: 0;}
.link:hover { color: var(--primary2); text-decoration: underline; }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0;
    background-color: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(6px);
    z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-content {
    background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
    border: 1px solid var(--border); width: 100%; max-width: 400px; overflow: hidden;
    transform: scale(0.95) translateY(10px); opacity: 0; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.active .modal-content { transform: scale(1) translateY(0); opacity: 1; }

.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); display: flex; align-items: center; }
.modal-close { width: 44px; height: 44px; display: grid; place-items: center; background: var(--surface3); color: var(--muted); border-radius: 50%; transition: all 0.2s; border: none; cursor: pointer;}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 24px; }

.flex-row { display: flex; gap: 12px; margin-top: 16px; }
.flex-1 { flex: 1; }

/* Toast */
.toast {
    position: fixed; top: 24px; left: 50%; transform: translate(-50%, -150%);
    background: var(--surface2); color: var(--text); padding: 12px 24px;
    border-radius: 9999px; box-shadow: var(--shadow); border: 1px solid var(--border);
    font-size: 14px; font-weight: 600;
    display: flex; align-items: center; z-index: 80; pointer-events: none; opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.toast-error { background: var(--badSoft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, var(--border));}
.toast.toast-success { background: var(--okSoft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--border));}
.toast.toast-info { background: var(--primarySoft); color: var(--primary2); border-color: color-mix(in srgb, var(--primary) 30%, var(--border));}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast svg { width: 20px; height: 20px; margin-right: 8px; }

@keyframes fadeIn { 0% { opacity: 0; transform: scale(0.95); } 100% { opacity: 1; transform: scale(1); } }
.animate-fade-in { animation: fadeIn 0.3s ease-out forwards; }

.message-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 16px;
    margin-top: 16px;
    color: var(--muted);
    font-size: 13px;
}

.radio-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.radio-btn {
    padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border2);
    text-align: center; font-size: 13px; font-weight: 600; color: var(--muted);
    transition: all 0.2s; background: var(--surface); cursor: pointer; display: block; width: 100%;
}
.radio-label { position: relative; display: block; cursor: pointer; }
.radio-label input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.radio-label input[type="radio"]:checked + .radio-btn {
    background: var(--primarySoft);
    color: var(--primary);
    border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}

.icon-circle {
    width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center;
    margin-bottom: 24px; border: 1px solid;
}
.icon-circle.success { background: var(--okSoft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.icon-circle.warning { background: var(--warnSoft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, var(--border)); }