/* Problem 91 VN — web port of the Android visual novel.
   Colours and dimensions mirror res/drawable/*.xml and res/layout/*.xml. */

:root {
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --accent: #3b82f6;
    --accent-2: #0ea5e9;

    --panel-bg: rgba(17, 17, 17, 0.54);
    --panel-border: rgba(255, 255, 255, 0.33);
    --radius: 14px;

    --text: #ffffff;
    --text-soft: rgba(255, 255, 255, 0.8);
    --text-faint: rgba(255, 255, 255, 0.62);

    --menu-gradient: linear-gradient(180deg, #283142 0%, #1e2533 52%, #111827 100%);
    --chapter-gradient: linear-gradient(45deg, #2a3850 0%, #1a2232 55%, #101722 100%);
    --transition-gradient: linear-gradient(120deg, #3a2438 0%, #24354a 55%, #101722 100%);

    --content-width: 860px;
}

* {
    box-sizing: border-box;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: #111827;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    min-height: 100dvh;
}

body.has-modal {
    overflow: hidden;
}

[hidden] {
    display: none !important;
}

button {
    font-family: inherit;
}

::selection {
    background: rgba(59, 130, 246, 0.5);
}

/* ------------------------------------------------------------------ */
/* Screens                                                             */
/* ------------------------------------------------------------------ */

.screen {
    min-height: 100dvh;
}

.screen--menu {
    background: var(--menu-gradient);
}

.screen--loading,
.screen--error {
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--menu-gradient);
}

.screen--novel {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--chapter-gradient);
}

.screen--transition {
    background: var(--transition-gradient);
}

/* ------------------------------------------------------------------ */
/* Shared panel                                                        */
/* ------------------------------------------------------------------ */

.panel {
    margin: 0;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
    width: 100%;
    padding: 14px 22px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    cursor: pointer;
    transition: filter 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid #a5c8ff;
    outline-offset: 3px;
}

.btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    box-shadow: none;
}

.btn--filled {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    box-shadow: 0 8px 22px rgba(14, 165, 233, 0.22);
}

.btn--filled:hover:not(:disabled) {
    filter: brightness(1.08);
}

.btn--outlined {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.45);
    color: #eaf3ff;
}

.btn--outlined:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(17, 17, 17, 0.5);
    color: #fff;
    cursor: pointer;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover {
    background: rgba(30, 30, 30, 0.72);
    border-color: rgba(255, 255, 255, 0.4);
}

.icon-button:focus-visible {
    outline: 2px solid #a5c8ff;
    outline-offset: 2px;
}

.icon-button--muted {
    color: rgba(255, 255, 255, 0.55);
}

/* ------------------------------------------------------------------ */
/* Main menu                                                           */
/* ------------------------------------------------------------------ */

.menu {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
    padding: clamp(30px, 8vh, 92px) 24px 26px;
}

.menu__title {
    margin: 0;
    text-align: center;
    font-size: clamp(34px, 5vw, 46px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.menu__subtitle {
    margin: 12px 0 0;
    text-align: center;
    font-size: 16px;
    color: var(--text-soft);
}

.menu__language {
    margin-top: 28px;
}

.menu__label {
    margin: 0 0 10px;
    font-size: 14px;
    color: #fff;
}

.segmented {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.03);
}

.segmented__btn {
    padding: 9px 24px;
    border: 0;
    background: transparent;
    color: #dfe8f5;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented__btn + .segmented__btn {
    border-left: 1px solid rgba(255, 255, 255, 0.25);
}

.segmented__btn:hover {
    background: rgba(255, 255, 255, 0.07);
}

.segmented__btn[aria-pressed="true"] {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.5) 0%, rgba(14, 165, 233, 0.38) 100%);
    color: #fff;
}

.segmented__btn:focus-visible {
    outline: 2px solid #a5c8ff;
    outline-offset: -4px;
}

.menu__status {
    margin-top: 22px;
    padding: 16px;
    font-size: 15px;
    line-height: 1.55;
}

.menu__actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.menu__footer {
    margin: auto 0 0;
    padding-top: 40px;
    text-align: center;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-faint);
}

/* ------------------------------------------------------------------ */
/* Novel screen                                                        */
/* ------------------------------------------------------------------ */

.novel__bg {
    position: absolute;
    inset: 0;
    background: var(--chapter-gradient);
}

.novel__scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}

.novel__content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: var(--content-width);
    height: 100%;
    margin: 0 auto;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.novel__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    margin-bottom: 8px;
}

.novel__title {
    flex: 0 0 auto;
    padding: 10px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.novel__music-hint {
    flex: 0 0 auto;
    margin-top: 6px;
    padding: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
}

.chat {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
    overscroll-behavior: contain;
}

.chat::-webkit-scrollbar {
    width: 8px;
}

.chat::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
}

.line {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    animation: line-in 0.26s ease both;
}

.line--narration {
    align-items: center;
}

.line--instant {
    animation: none;
}

.line--message {
    align-items: flex-start;
}

.bubble {
    max-width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 16px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble--message {
    max-width: min(340px, 88%);
    background: rgba(24, 37, 56, 0.67);
    border: 1px solid rgba(184, 212, 255, 0.33);
}

.bubble--narration {
    max-width: min(320px, 92%);
    background: rgba(42, 42, 42, 0.53);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #f5f5f5;
    font-size: 14px;
    font-style: italic;
    text-align: center;
}

.speaker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 4px 2px;
    padding: 2px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.speaker:hover .speaker__name {
    text-decoration: underline;
}

.speaker:focus-visible {
    outline: 2px solid #a5c8ff;
    outline-offset: 2px;
}

.avatar {
    display: grid;
    place-items: center;
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    border: 1px solid rgba(255, 255, 255, 0.67);
    border-radius: 50%;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
}

.speaker__name {
    padding-right: 2px;
    color: #d2e6ff;
    font-size: 12px;
    font-weight: 700;
}

.tap-panel {
    flex: 0 0 auto;
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    font-size: 14px;
    line-height: 1.45;
    color: #fff;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.tap-panel:hover {
    background: rgba(34, 34, 34, 0.62);
}

.tap-panel:focus-visible {
    outline: 2px solid #a5c8ff;
    outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/* Transition / ending                                                 */
/* ------------------------------------------------------------------ */

.transition {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
    padding: max(32px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
    text-align: center;
}

.transition__title {
    margin: 0;
    font-size: clamp(28px, 4.4vw, 36px);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.spinner {
    width: 44px;
    height: 44px;
    margin: 24px auto;
    border: 4px solid rgba(255, 255, 255, 0.16);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.transition__message {
    width: 100%;
    margin-top: 4px;
    padding: 16px;
    font-size: 16px;
    line-height: 1.55;
    text-align: left;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.transition__actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    margin-top: auto;
    padding-top: 28px;
}

/* ------------------------------------------------------------------ */
/* Loading / error                                                     */
/* ------------------------------------------------------------------ */

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.86);
}

.loading__text {
    margin: 0;
    font-size: 15px;
}

.error {
    width: 100%;
    max-width: 560px;
    padding: 24px;
}

.error__title {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
}

.error__body {
    margin: 0;
    font-size: 15px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.86);
}

.error__hint {
    margin: 16px 0 0;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    color: #cfe3ff;
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ */
/* Speaker profile modal                                               */
/* ------------------------------------------------------------------ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    overflow-y: auto;
    background: var(--menu-gradient);
    animation: fade-in 0.18s ease both;
}

.modal__inner {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
    padding: max(22px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}

.modal__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.profile__header {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

.profile__name {
    margin: 14px 0 0;
    font-size: clamp(28px, 4vw, 34px);
    font-weight: 700;
    line-height: 1.2;
}

.profile__role {
    margin: 6px 0 0;
    color: #b9d9ff;
    font-size: 15px;
    line-height: 1.45;
}

.profile__lore {
    flex: 1 1 auto;
    margin-top: 16px;
    padding: 14px;
    font-size: 16px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ */
/* Toast                                                               */
/* ------------------------------------------------------------------ */

.toast {
    position: fixed;
    left: 50%;
    bottom: max(88px, calc(env(safe-area-inset-bottom) + 72px));
    z-index: 80;
    max-width: calc(100vw - 48px);
    padding: 10px 16px;
    transform: translateX(-50%);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    background: rgba(17, 17, 17, 0.92);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    animation: toast-in 0.18s ease both;
}

/* ------------------------------------------------------------------ */
/* Animations                                                          */
/* ------------------------------------------------------------------ */

@keyframes line-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

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

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */

@media (max-width: 420px) {
    .menu {
        padding-left: 18px;
        padding-right: 18px;
    }

    .novel__content {
        padding-left: 10px;
        padding-right: 10px;
    }

    .bubble--message {
        font-size: 15px;
    }

    .bubble--narration {
        font-size: 13.5px;
    }
}
