/* Cooly student interface — coordinated with the staff panel */
:root {
    color-scheme: light;
    --page: #f8f7f2;
    --surface: #ffffff;
    --surface-soft: #f2f3eb;
    --ink: #222d25;
    --muted: #758077;
    --green: #315d46;
    --green-dark: #244735;
    --green-light: #e7efe8;
    --border: #e5e8df;
    --danger: #a83f3f;
    --danger-bg: #fff0ef;
    --success: #286344;
    --success-bg: #eaf5ed;
    --warning: #85641b;
    --warning-bg: #fff6dd;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --shadow: 0 18px 60px rgba(35, 52, 39, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-width: 320px;
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background:
        radial-gradient(ellipse at 8% 10%, rgba(231, 239, 232, 0.85), transparent 32rem),
        radial-gradient(ellipse at 95% 90%, rgba(242, 243, 235, 0.9), transparent 30rem),
        var(--page);
    color: var(--ink);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
}

body::before,
body::after {
    position: fixed;
    z-index: -1;
    width: 220px;
    height: 220px;
    border: 1px solid rgba(49, 93, 70, 0.08);
    border-radius: 50%;
    content: "";
    pointer-events: none;
}

body::before {
    top: -120px;
    right: -65px;
}

body::after {
    bottom: -135px;
    left: -75px;
}

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

button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Main page layout */
.app {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 44px 22px;
}

/* Main card */
.card {
    position: relative;
    width: min(100%, 480px);
    padding: clamp(26px, 5vw, 44px);
    overflow: hidden;
    border: 1px solid rgba(229, 232, 223, 0.95);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
    animation: card-enter 420ms ease both;
}

.card::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--green-dark), #78947b, #c7d8c7);
    content: "";
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typography */
h1 {
    margin: 0;
    color: var(--green);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(42px, 7vw, 54px);
    font-weight: 600;
    letter-spacing: -2.3px;
    line-height: 1.12;
    text-align: center;
}

.subtitle {
    margin: 8px 0 34px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.25px;
    text-align: center;
}

h2 {
    margin: 0 0 9px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(25px, 4vw, 30px);
    font-weight: 500;
    letter-spacing: -0.65px;
    line-height: 1.3;
}

.description {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.8;
}

/* Forms */
form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

input,
select,
textarea {
    display: block;
    width: 100%;
    min-height: 49px;
    padding: 13px 15px;
    border: 1px solid #dfe4db;
    border-radius: var(--radius-sm);
    outline: none;
    background: #fff;
    color: var(--ink);
    transition:
        border-color 160ms ease,
        box-shadow 160ms ease,
        background 160ms ease;
}

input::placeholder,
textarea::placeholder {
    color: #9aa39a;
}

input:hover,
select:hover,
textarea:hover {
    border-color: #c4d0c4;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(49, 93, 70, 0.12);
}

textarea {
    min-height: 130px;
    resize: vertical;
    line-height: 1.65;
}

label {
    display: block;
    margin: 2px 0 -5px;
    color: #39483c;
    font-size: 13px;
    font-weight: 700;
}

/* Buttons */
button {
    min-height: 47px;
    padding: 12px 17px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--green);
    color: #fff;
    font-size: 14px;
    font-weight: 750;
    transition:
        background 160ms ease,
        border-color 160ms ease,
        color 160ms ease,
        transform 160ms ease,
        box-shadow 160ms ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: var(--green-dark);
    box-shadow: 0 5px 14px rgba(36, 71, 53, 0.12);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:focus-visible {
    outline: 3px solid rgba(49, 93, 70, 0.25);
    outline-offset: 3px;
}

/* Registration and login options */
#auth-options {
    display: grid;
    gap: 12px;
}

#auth-options h2,
#auth-options .description {
    grid-column: 1;
}

#show-login {
    border-color: var(--border);
    background: var(--surface-soft);
    color: var(--green-dark);
}

#show-login:hover:not(:disabled) {
    border-color: #c6d4c7;
    background: var(--green-light);
    box-shadow: none;
}

#back-to-options,
#back-to-options-from-login,
#resend-otp {
    border-color: var(--border);
    background: #fff;
    color: var(--muted);
    box-shadow: none;
}

#back-to-options:hover:not(:disabled),
#back-to-options-from-login:hover:not(:disabled),
#resend-otp:hover:not(:disabled) {
    border-color: #c6d4c7;
    background: var(--surface-soft);
    color: var(--green-dark);
}

/* Status and error messages */
#message,
#chat-message {
    overflow-wrap: anywhere;
    margin: 16px 0 0;
    padding: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
    text-align: center;
}

#message:empty,
#chat-message:empty {
    display: none;
}

/* Placement form */
#placement-form {
    gap: 13px;
}

#placement-form select {
    margin-bottom: 4px;
}

/* Assessment */
#question {
    margin: 0 0 18px;
    padding: 17px 18px;
    border: 1px solid #e0e8de;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 16px;
    font-weight: 650;
    line-height: 1.8;
    overflow-wrap: anywhere;
}

#assessment-area textarea {
    margin-bottom: 12px;
}

/* Chat page */
.chat-card {
    width: min(100%, 760px);
    padding: clamp(22px, 4vw, 38px);
    text-align: center;
}

.chat-card h1 {
    font-size: 43px;
}

.chat-card .subtitle {
    margin-bottom: 24px;
}

#level-text {
    display: inline-block;
    max-width: 100%;
    margin: 10px auto 24px;
    padding: 7px 13px;
    border: 1px solid #dce7dc;
    border-radius: 999px;
    background: var(--green-light);
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 700;
}

/* Conversation area */
.chat-messages {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: min(52vh, 480px);
    min-height: 280px;
    margin: 0 0 16px;
    padding: 18px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background:
        linear-gradient(rgba(242, 243, 235, 0.42), rgba(242, 243, 235, 0.42)),
        #fbfcf9;
    text-align: left;
    overscroll-behavior: contain;
    scrollbar-color: #c5d2c5 transparent;
    scrollbar-width: thin;
}

.chat-message {
    max-width: min(84%, 520px);
    margin: 0 0 12px;
    padding: 12px 15px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    text-align: left;
}

.student-message {
    align-self: flex-end;
    margin-left: auto;
    border: 1px solid var(--green);
    border-bottom-right-radius: 5px;
    background: var(--green);
    color: #fff;
}

.assistant-message {
    align-self: flex-start;
    margin-right: auto;
    border: 1px solid #e4e8df;
    border-bottom-left-radius: 5px;
    background: #fff;
    color: var(--ink);
}

/* Chat input */
.chat-input-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
    text-align: left;
}

.chat-input-area textarea {
    min-height: 54px;
    max-height: 150px;
    margin: 0;
    padding: 14px 15px;
}

#send-message {
    min-width: 94px;
    min-height: 54px;
}

.chat-card #chat-message {
    text-align: left;
}

/* Prevent overflow */
.card > *,
form > *,
.chat-input-area > * {
    min-width: 0;
}

/* Mobile layout */
@media (max-width: 600px) {
    .app {
        align-items: flex-start;
        padding: 22px 14px;
    }

    .card {
        margin: auto 0;
        padding: 29px 21px 24px;
        border-radius: 20px;
    }

    h1 {
        font-size: 45px;
    }

    .subtitle {
        margin-bottom: 28px;
    }

    h2 {
        font-size: 26px;
    }

    .description {
        margin-bottom: 20px;
        font-size: 13px;
    }

    input,
    select,
    textarea {
        min-height: 48px;
        font-size: 16px;
    }

    button {
        min-height: 48px;
    }

    .chat-card {
        padding: 23px 15px 18px;
    }

    .chat-card h1 {
        font-size: 39px;
    }

    .chat-card .subtitle {
        margin-bottom: 18px;
    }

    .chat-messages {
        height: 48vh;
        min-height: 260px;
        padding: 12px;
    }

    .chat-message {
        max-width: 92%;
        padding: 10px 12px;
        font-size: 13px;
    }

    .chat-input-area {
        grid-template-columns: minmax(0, 1fr);
        gap: 9px;
    }

    .chat-input-area textarea {
        min-height: 86px;
    }

    #send-message {
        width: 100%;
        min-height: 47px;
    }
}

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