:root {
    --grid-gap: 4px;
    --grid-padding: 4px;
    --cell-border: 1px solid rgba(255, 255, 255, 0.18);
    --cell-bg: rgba(255, 255, 255, 0.06);
    --cell-label-size: clamp(9px, 0.8vw, 12px);
}

* {
    box-sizing: border-box;
}

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

body {
    min-height: 100dvh;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    background: #111;
    color: #fff;
}

.screen-grid {
    width: 100vw;
    height: 100dvh;
    gap: var(--grid-gap);
    padding: var(--grid-padding);
}

.layout-h {
    display: none;
    grid-template-columns: repeat(15, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
}

.layout-v {
    display: none;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(15, minmax(0, 1fr));
}

/* Each grid item is also a flex container. */
.grid-cell,
.grid-zone {
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Generic zone placement convention:
   --row: starting row (1-based)
   --col: starting column (1-based)
   --rows: number of rows to span
   --cols: number of columns to span
*/
.grid-zone {
    grid-row: var(--row) / span var(--rows, 1);
    grid-column: var(--col) / span var(--cols, 1);
}

/* Diagnostic cell styling. Remove this class from production layouts. */
.debug-cell {
    border: var(--cell-border);
    background: var(--cell-bg);
    font-size: var(--cell-label-size);
    line-height: 1;
    user-select: none;
}

.debug-title {
    position: fixed;
    z-index: 1000;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.65);
    font-size: 12px;
    pointer-events: none;
}

@media (orientation: landscape) {
    .layout-h {
        display: grid;
    }

    .layout-v {
        display: none;
    }
}

@media (orientation: portrait) {
    .layout-h {
        display: none;
    }

    .layout-v {
        display: grid;
    }
}

/* Fallback for environments that do not report orientation reliably. */
@media (min-aspect-ratio: 1/1) {
    .layout-h {
        display: grid;
    }
}

@media (max-aspect-ratio: 1/1) {
    .layout-v {
        display: grid;
    }
}

/* Grid test interaction. */
.grid-test {
    touch-action: none;
}

.debug-cell.is-lit {
    background: #fff;
    color: #111;
    border-color: #fff;
}

/* Temporary root page until the first real KIRE ONLINE screen is built. */
.home-placeholder {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.home-placeholder__content {
    text-align: center;
}

.home-placeholder__content a {
    color: inherit;
}

/* Landing page ----------------------------------------------------------- */
.landing-page {
    background: #071723;
}

.landing-page .screen-grid {
    gap: 0;
    padding: 0;
}

.cover-frame {
    padding: clamp(4px, 0.7vmin, 10px);
}

.cover-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.main-button {
    align-self: stretch;
    justify-self: stretch;
    margin: clamp(6px, 1vmin, 12px);
    border: 1px solid #c8792d;
    border-radius: 6px;
    background: linear-gradient(#173044, #0b1d2a);
    color: #f2c27c;
    text-decoration: none;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(12px, 1.7vmin, 20px);
    font-weight: 700;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}

.main-button:hover,
.main-button:focus-visible {
    background: linear-gradient(#21445e, #102a3d);
    outline: 2px solid rgba(242, 194, 124, 0.55);
    outline-offset: 2px;
}

.main-button:active {
    transform: translateY(1px);
}

/* Language selector. One grid cell with a floating 2x3 menu. */
.language-selector-h {
    --row: 1;
    --col: 15;
    --rows: 1;
    --cols: 1;
}

.language-selector-v {
    --row: 1;
    --col: 10;
    --rows: 1;
    --cols: 1;
}

.language-selector {
    position: relative;
    z-index: 50;
    overflow: visible;
}

.language-button {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: clamp(2px, .45vmin, 6px);
    border: 0;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.language-flag {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.language-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 300%;
    height: 200%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    justify-items: stretch;
    gap: 3px;
    padding: 3px;
    border: 1px solid rgba(200, 121, 45, 0.75);
    border-radius: 7px;
    background: rgba(5, 19, 30, 0.96);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .32);
}

.language-menu[hidden] {
    display: none;
}

.language-option {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: clamp(2px, .35vmin, 5px);
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.language-option:hover,
.language-option:focus-visible,
.language-option.is-selected {
    border-color: #c8792d;
    background-color: rgba(255, 255, 255, 0.08);
    outline: none;
}


/* Authentication page ---------------------------------------------------- */
.auth-page {
    background: #071723;
}

.auth-page .screen-grid {
    gap: 0;
    padding: 0;
}

.auth-panel {
    min-width: 0;
    min-height: 0;
    align-items: stretch;
    justify-content: stretch;
    padding: clamp(6px, 1vmin, 12px);
}

.auth-card {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: clamp(7px, 1.2vmin, 14px);
    padding: clamp(12px, 1.8vmin, 22px);
    overflow: hidden;
    border: 1px solid rgba(200, 121, 45, 0.8);
    border-radius: 10px;
    background:
        linear-gradient(
            180deg,
            rgba(20, 45, 62, 0.96),
            rgba(7, 23, 35, 0.98)
        );
}

.auth-tabs {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.auth-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 10px;
    border: 1px solid rgba(200, 121, 45, 0.55);
    border-radius: 6px;
    color: #c9b186;
    text-decoration: none;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(11px, 1.4vmin, 16px);
    font-weight: 700;
    letter-spacing: 0.08em;
    background: rgba(4, 18, 28, 0.55);
}

.auth-tab.is-active,
.auth-tab:hover,
.auth-tab:focus-visible {
    color: #f2c27c;
    border-color: #c8792d;
    background: rgba(28, 58, 78, 0.9);
    outline: none;
}

.auth-logo {
    flex: 0 1 auto;
    display: block;
    width: min(74%, 360px);
    max-height: 21%;
    margin: 0 auto;
    object-fit: contain;
}

.auth-form {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: clamp(7px, 1.1vmin, 13px);
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    color: #d9c7a3;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(11px, 1.35vmin, 15px);
}

.form-field input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid rgba(200, 121, 45, 0.55);
    border-radius: 6px;
    background: rgba(3, 14, 22, 0.78);
    color: #fff;
    font: inherit;
    outline: none;
}

.form-field input:focus {
    border-color: #d99a55;
    box-shadow: 0 0 0 2px rgba(217, 154, 85, 0.18);
}

.auth-submit {
    flex: 0 0 auto;
    min-height: 40px;
    margin: 2px 0 0;
}

.form-message {
    flex: 0 0 auto;
    padding: 7px 9px;
    border-radius: 6px;
    font-size: clamp(10px, 1.2vmin, 14px);
    text-align: center;
}

.form-message.is-error {
    border: 1px solid rgba(220, 95, 80, 0.8);
    background: rgba(95, 25, 22, 0.45);
}

.form-message.is-success {
    border: 1px solid rgba(90, 170, 110, 0.75);
    background: rgba(20, 75, 42, 0.45);
}

/* The vertical auth frame is taller, so the logo can be slightly more generous. */
.layout-v .auth-logo {
    width: min(82%, 340px);
    max-height: 19%;
}

.layout-v .auth-card {
    gap: clamp(6px, 1vmin, 12px);
    padding: clamp(10px, 1.6vmin, 18px);
}
