* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg-space: #07111f;
    --bg-deep: #030711;
    --card-inner: rgba(255, 255, 255, 0.085);
    --key-bg: rgba(255, 255, 255, 0.12);
    --primary-green: #6ef2c2;
    --primary-cyan: #70d6ff;
    --primary-yellow: #ffe27a;
    --soft-red: #ff7d8a;
    --text-main: #eef7ff;
    --text-muted: rgba(238, 247, 255, 0.74);
    --input-bg: rgba(110, 242, 194, 0.12);
    --line: rgba(173, 230, 255, 0.16);
    --shadow-color: rgba(0, 0, 0, 0.34);
    --accent: #7eb6ff;
    --accent-deep: #92a7ff;
    --panel-glow: rgba(110, 242, 194, 0.12);
    --panel-blue: rgba(126, 182, 255, 0.18);
    --focus-ring: rgba(110, 242, 194, 0.74);
}

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at 16% 14%, rgba(112, 214, 255, 0.23), transparent 24%),
        radial-gradient(circle at 84% 12%, rgba(110, 242, 194, 0.18), transparent 22%),
        radial-gradient(circle at 74% 72%, rgba(255, 226, 122, 0.12), transparent 24%),
        radial-gradient(circle at 42% 48%, rgba(146, 167, 255, 0.10), transparent 30%),
        linear-gradient(160deg, #020611 0%, #091225 36%, #102142 72%, #132d4d 100%);
    font-family: 'Segoe Print', 'Trebuchet MS', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: var(--text-main);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(circle, rgba(255,255,255,.72) 0 1px, transparent 1.6px),
        radial-gradient(circle, rgba(112,214,255,.38) 0 1px, transparent 1.5px),
        linear-gradient(125deg, rgba(255,255,255,.04), transparent 24%, rgba(255,255,255,.02) 48%, transparent 74%);
    background-size: 88px 88px, 132px 132px, 240px 240px;
    background-position: 8px 14px, 42px 61px, 0 0;
    opacity: .32;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 0%, rgba(112, 214, 255, 0.16), transparent 34%),
        radial-gradient(circle at 10% 90%, rgba(110, 242, 194, 0.10), transparent 28%);
    mix-blend-mode: screen;
    opacity: .8;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button, a, label, input { -webkit-tap-highlight-color: rgba(119, 224, 182, .22); }

button,
.return-home-button,
.console-button,
.btn-main,
.back-btn,
.danger-btn,
.key,
.type-options label,
.tone-options label,
.option-card,
.play-button {
    touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.type-options input:focus-visible + span,
.tone-options input:focus-visible + span,
.term-options input:focus-visible + span,
.carry-options input:focus-visible + span,
.sound-control:focus-within {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px;
}
.hidden { display: none !important; }

#app {
    position: relative;
    width: 100%;
}

.page-shell {
    width: 100%;
    display: grid;
    gap: 16px;
}

.workbench-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr);
    gap: 16px;
    align-items: stretch;
}

.workbench-grid-balanced {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.workbench-main,
.workbench-side {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.workbench-side {
    gap: 16px;
}

.console-page {
    position: relative;
    z-index: 1;
}

.console-panel {
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(10, 22, 45, .88), rgba(10, 18, 38, .74));
    border: 1px solid var(--line);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 18px 46px rgba(0,0,0,.24), 0 0 0 1px rgba(112,214,255,.04), 0 0 42px rgba(112,214,255,.08);
    backdrop-filter: blur(16px);
}

.console-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(126,182,255,.055), transparent 28%, transparent 72%, rgba(119,224,182,.055)),
        linear-gradient(180deg, rgba(255,255,255,.035), transparent 24%);
}

.console-kicker,
.section-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .22em;
    text-transform: uppercase;
}

.console-kicker::before,
.section-eyebrow::before {
    content: "";
    width: 26px;
    height: 1px;
    background: currentColor;
    opacity: .75;
}

.card-title {
    margin: 0;
    font-size: clamp(28px, 4vw, 38px);
    line-height: 1.08;
    letter-spacing: -.05em;
}

.card-copy {
    margin: 10px 0 0;
    color: var(--text-muted);
    line-height: 1.7;
}

.page-heading {
    position: relative;
    z-index: 1;
}

.page-backbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.page-intro {
    padding: 18px 20px;
    border-radius: 28px;
}

.page-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 14px 16px;
}

.page-title {
    margin: 0;
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.06;
    letter-spacing: -.06em;
}

.page-subtitle {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.65;
}

.panel-title,
.section-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.panel-title {
    margin-bottom: 16px;
}

.section-label {
    margin: 0 0 10px;
    color: var(--text-muted);
    font-size: 14px;
}

.panel-title strong,
.section-label strong {
    color: var(--text-main);
    font-size: 18px;
}

.panel-title small,
.section-label small {
    color: var(--text-muted);
    font-size: 13px;
}

.section-label-stackless {
    margin-bottom: 0;
}

.sound-control {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 118px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255,255,255,.08);
    color: rgba(238,247,255,.82);
    font-size: 13px;
    cursor: pointer;
}

.sound-control input { position: absolute; opacity: 0; pointer-events: none; }

.sound-switch {
    width: 38px;
    height: 22px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
}

.sound-switch::after {
    content: "";
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(238,247,255,.58);
    transition: margin .15s, background .15s;
}

.sound-control input:checked + .sound-switch {
    background: rgba(119,224,182,.22);
    box-shadow: 0 0 22px rgba(119,224,182,.22);
}

.sound-control input:checked + .sound-switch::after {
    margin-left: 16px;
    background: var(--primary-green);
}

.type-options input,
.tone-options input,
.term-options input,
.carry-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.type-options label,
.tone-options label,
.term-options label,
.carry-options label {
    cursor: pointer;
}

.type-options span,
.tone-options span,
.term-options span,
.carry-options span {
    display: block;
    padding: 13px 10px;
    text-align: center;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.075);
    color: var(--text-main);
    font-size: 17px;
    font-weight: 800;
    transition: background .16s ease, border-color .16s ease, color .16s ease, transform .12s ease, box-shadow .16s ease;
}

.type-options label:hover span,
.tone-options label:hover span,
.term-options label:hover span,
.carry-options label:hover span {
    border-color: rgba(119,224,182,.34);
    background: rgba(255,255,255,.11);
}

.type-options input:checked + span,
.tone-options input:checked + span,
.term-options input:checked + span,
.carry-options input:checked + span {
    background: var(--primary-green);
    color: #102019;
    border-color: var(--primary-green);
    box-shadow: 0 0 28px rgba(119,224,182,.26);
}

.field-card,
.metric-card {
    position: relative;
    z-index: 1;
    min-height: 84px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255,255,255,.07);
}

.field-card span,
.metric-card span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 8px;
}

.field-card strong,
.metric-card b {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -.04em;
}

.field-card input[type="number"] {
    width: 84px;
    padding: 7px 4px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.10);
    color: var(--text-main);
    font-size: 20px;
    font-weight: 800;
    text-align: center;
}

.field-card input[type="number"]:focus-visible,
.challenge-card input:focus-visible {
    border-color: rgba(119,224,182,.6);
    background: rgba(119,224,182,.13);
}

.history-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.history-row:first-of-type { border-top: none; }
.history-main { color: var(--text-main); font-weight: 700; }
.history-sub,
.empty-history { color: var(--text-muted); }

.history-badge {
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--primary-green);
    font-weight: 800;
    white-space: nowrap;
}

.form-error {
    color: var(--soft-red);
    min-height: 20px;
    text-align: center;
    font-size: 15px;
    margin-top: 12px;
}

.form-error.visible {
    min-height: auto;
    padding: 10px 12px;
    border: 1px solid rgba(255, 125, 138, .4);
    border-radius: 14px;
    background: rgba(255, 125, 138, .12);
    font-weight: 800;
}

.btn-main {
    border: none;
    width: 100%;
    padding: 18px;
    border-radius: 18px;
    background: var(--primary-green);
    color: #102019;
    font-size: 20px;
    font-weight: 900;
    box-shadow: 0 0 24px rgba(119,224,182,.18), 0 14px 28px rgba(0,0,0,.26);
    cursor: pointer;
}

.back-btn,
.danger-btn {
    border: 1px solid var(--line);
    background: rgba(255,255,255,.08);
    color: var(--text-main);
    font-weight: 850;
    cursor: pointer;
}

.back-btn {
    padding: 10px 14px;
    border-radius: 999px;
}

.danger-btn {
    border-color: rgba(255, 125, 138, .26);
    border-radius: 16px;
    background: rgba(255, 125, 138, .075);
    color: rgba(255, 180, 188, .9);
    padding: 12px 10px;
}

.progress-capsule {
    display: flex;
    gap: 12px;
    padding: 10px 18px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.06);
    box-shadow: 0 14px 34px var(--shadow-color);
}

.progress-capsule span {
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--input-bg);
}

.challenge-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(5, 8, 18, .72);
    backdrop-filter: blur(10px);
}

.challenge-card {
    width: min(420px, 100%);
    padding: 24px;
    background: rgba(18, 26, 47, .96);
    border: 1px solid var(--line);
    border-radius: 28px;
}

.challenge-card h2 { margin: 0 0 8px; color: var(--soft-red); }
.challenge-card p { color: var(--text-muted); margin: 0 0 16px; }
.challenge-question { font-size: 40px; font-weight: 950; letter-spacing: -.05em; margin-bottom: 14px; }
.challenge-card input {
    width: 100%;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.10);
    color: var(--text-main);
    font-size: 24px;
    font-weight: 850;
    text-align: center;
}

.challenge-error { min-height: 22px; color: var(--soft-red); margin-top: 10px; }

.challenge-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.challenge-actions button {
    border: 0;
    border-radius: 16px;
    padding: 13px;
    font-weight: 900;
    cursor: pointer;
}

.challenge-cancel { background: rgba(255,255,255,.10); color: var(--text-main); }
.challenge-confirm { background: var(--soft-red); color: #210B10; }

.toast-tip {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, calc(-50% - 12px));
    min-width: min(320px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    padding: 14px 18px;
    border-radius: 18px;
    border: 1px solid rgba(255, 125, 138, .5);
    background: rgba(34, 10, 16, .94);
    color: #ffd8de;
    text-align: center;
    font-size: 17px;
    font-weight: 900;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

.toast-tip.visible { opacity: 1; transform: translate(-50%, -50%); }

.return-home-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    opacity: .88;
}

.return-home-link:hover {
    color: var(--text-main);
    opacity: 1;
}

.return-home-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.08);
    color: var(--text-main);
    font-size: 14px;
    font-weight: 700;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}

.return-home-button:hover {
    border-color: rgba(119,224,182,.32);
    color: var(--primary-green);
}

.console-button,
.btn-main {
    transition: background .16s ease, border-color .16s ease, transform .12s ease, box-shadow .16s ease;
}

.console-button:hover,
.btn-main:hover,
.back-btn:hover,
.danger-btn:hover,
.nav-card:hover {
    border-color: rgba(119,224,182,.36);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 18px 46px rgba(0,0,0,.24), 0 0 20px rgba(119,224,182,.08);
}

.btn-main:hover,
.console-button:hover {
    transform: translateY(-1px);
}

.danger-btn:hover {
    border-color: rgba(255, 125, 138, .44);
    background: rgba(255, 125, 138, .12);
    color: #ffd8de;
}

@media (max-width: 920px) {
    .workbench-grid {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}
