/*
 * The platform's own screens: the game wall, a game opened from it, and the room.
 * The platform is dark and quiet; colour, type and shape come from each game's `look`
 * (metadata.look), applied as CSS variables on any element with class "look".
 */

:root {
    --p-bg: #0F1022;
    --p-tile: #1B1D3A;
    --p-tile-2: #2A2D55;
    --p-ink: #FFFFFF;
    --p-muted: #A9AEC8;
}

/* Which half of the page shows: the shell (wall and room) or a running game. */
html[data-view="shell"] #game-container { display: none; }
html[data-view="game"] #shell { display: none; }
html[data-view="shell"] body {
    margin: 0;
    padding: 0;
    background: var(--p-bg);
}

#shell {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'IBM Plex Sans Hebrew', system-ui, -apple-system, sans-serif;
    color: var(--p-ink);
    -webkit-tap-highlight-color: transparent;
}
/* Low specificity on purpose: it only has to undo styles.css's bare h1/h2/h3 rules. */
:where(#shell) h1, :where(#shell) h2, :where(#shell) h3 {
    margin: 0;
    background: none;
    -webkit-text-fill-color: currentColor;
    color: inherit;
    text-align: start;
    font-size: inherit;
}
#shell button, #shell input, #shell select { font-family: inherit; }
#shell .screen.active { animation: none; }

/* ---- The wall ---- */
#wall {
    max-width: 480px;
    margin: 0 auto;
    padding: 12px 12px 32px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.wall-group { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
/* A wide screen lays the wall's groups out side by side. */
@media (min-width: 900px) {
    #wall { max-width: 1000px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 28px; align-items: start; padding: 28px 28px 48px; }
    .wall-group .wall-section { margin-top: 0; }
}
@media (min-width: 1400px) {
    #wall { max-width: 1480px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.wall-head {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.p-tile {
    box-sizing: border-box;
    padding: 14px;
    background: var(--p-tile);
    border-radius: 18px;
}
.wall-title, .wall-size {
    min-height: 198px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.wall-brand { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 500; color: var(--p-muted); }
.wall-brand button { border: 0; background: none; color: var(--p-muted); font-size: 14px; padding: 6px 0; cursor: pointer; text-decoration: underline; }
.wall-title h1 { font-size: 28px; font-weight: 600; line-height: 1.12; }
.wall-title p { margin: 4px 0 0; font-size: 14px; color: var(--p-muted); }
.wall-size > div:first-child { font-size: 17px; font-weight: 600; }
.size-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.size-grid button {
    height: 54px;
    padding: 0;
    border: 0;
    border-radius: 14px;
    background: var(--p-tile-2);
    color: var(--p-ink);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
}
.size-grid button[aria-pressed="true"] { background: #FFFFFF; color: var(--p-bg); }

.wall-row { display: flex; align-items: center; gap: 10px; }
.wall-row > span { flex: 1; font-size: 16px; }
.p-btn {
    min-height: 48px;
    padding: 0 20px;
    border: 0;
    border-radius: 14px;
    background: #FFFFFF;
    color: var(--p-bg);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}
.p-btn.quiet { background: var(--p-tile-2); color: var(--p-ink); }
.p-btn:disabled { opacity: 0.45; cursor: default; }
.wall-auth { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.wall-auth p { margin: 0; font-size: 16px; }
.wall-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 16px; }

.wall-section { margin: 12px 4px 0; font-size: 16px; font-weight: 600; color: var(--p-muted); }
.mosaic {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: 94px;
    gap: 10px;
}

/* ---- A game's look: variables set from metadata.look ---- */
.look {
    --g-bg: var(--p-tile);
    --g-ink: #FFFFFF;
    --g-accent: #FFFFFF;
    --g-accent-ink: #0F1022;
    --g-muted: #A9AEC8;
    --g-line: #3A3D66;
    --g-surface: #2A2D55;
    --g-name: var(--g-accent);
    --g-display: 'IBM Plex Sans Hebrew', system-ui, sans-serif;
    --g-body: 'IBM Plex Sans Hebrew', system-ui, sans-serif;
    background: var(--g-bg);
    color: var(--g-ink);
    font-family: var(--g-body);
}
.look.font-show { --g-display: 'Karantina', 'IBM Plex Sans Hebrew', sans-serif; }
.look.font-serif { --g-display: 'Frank Ruhl Libre', Georgia, serif; }
.look.font-toy { --g-display: 'Fredoka', system-ui, sans-serif; --g-body: 'Fredoka', 'IBM Plex Sans Hebrew', system-ui, sans-serif; --g-name: var(--g-ink); }

/* ---- Tiles ---- */
.tile {
    position: relative;
    overflow: hidden;
    min-width: 0;
    margin: 0;
    padding: 0 14px 12px;
    border: 0;
    border-radius: 18px;
    cursor: pointer;
    text-align: start;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: transform 0.12s ease, opacity 0.2s ease;
}
.tile:active { transform: scale(0.96); }
.tile.dim { opacity: 0.22; }
.tile.shape-sharp { border-radius: 0; box-shadow: inset 0 0 0 5px var(--g-accent), 0 0 30px color-mix(in srgb, var(--g-accent) 25%, transparent); padding-inline: 18px; }
.tile.shape-soft { border-radius: 12px; box-shadow: inset 0 0 0 4px var(--g-bg), inset 0 0 0 6px var(--g-accent), 0 12px 26px rgba(0, 0, 0, 0.5); padding-inline: 18px; }
.tile.shape-round { border-radius: 24px; border: 3px solid var(--g-ink); box-shadow: 0 6px 0 color-mix(in srgb, var(--g-bg) 62%, #000); }

.t-wide { grid-column: span 4; grid-row: span 2; }
.t-main { grid-column: span 3; grid-row: span 2; }
.t-narrow { grid-column: span 1; grid-row: span 2; }
.t-strip { grid-column: span 4; grid-row: span 1; }
.t-tall { grid-column: span 2; grid-row: span 3; }
.t-square { grid-column: span 2; grid-row: span 2; }
.t-short { grid-column: span 2; grid-row: span 1; }

.tile-art { position: absolute; top: 0; left: 0; transform-origin: 0 0; pointer-events: none; direction: ltr; }
.tile-text { position: relative; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-name { font-family: var(--g-display); font-weight: 700; line-height: 1.05; color: var(--g-name); overflow-wrap: anywhere; }
.font-toy .tile-name { font-weight: 600; }
.tile-meta { font-family: 'IBM Plex Sans Hebrew', system-ui, sans-serif; font-size: 14px; color: var(--g-muted); }
.font-serif .tile-meta { color: var(--g-accent); }

.t-wide .tile-name { font-size: 32px; }
.t-main .tile-name { font-size: 28px; }
.t-tall .tile-name, .t-square .tile-name { font-size: 27px; }
.t-strip .tile-name { font-size: 24px; }
.t-short .tile-name { font-size: 21px; }
.font-show .tile-name { line-height: 0.82; white-space: nowrap; overflow-wrap: normal; }
.font-show.t-wide .tile-name { font-size: 112px; }
.font-show.t-main .tile-name { font-size: 104px; }
.font-show.t-tall .tile-name, .font-show.t-square .tile-name { font-size: 68px; }
.font-show.t-strip .tile-name { font-size: 62px; }
.font-show.t-short .tile-name { font-size: 46px; }

/* Low tiles: art on the left, words on the right. */
.t-strip, .t-short { justify-content: center; padding-bottom: 0; }
.t-strip .tile-text { max-width: 62%; }
.t-short .tile-text { max-width: 58%; }
.t-short .tile-meta { font-size: 13px; }

/* The narrow tile: its name runs up the side. */
.t-narrow, .tile.shape-sharp.t-narrow, .tile.shape-soft.t-narrow { padding: 14px 9px 10px; justify-content: stretch; }
.t-narrow .tile-text { flex: 1; justify-content: space-between; align-items: flex-start; }
.t-narrow .tile-name { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-size: 22px; line-height: 1; }
.font-show.t-narrow .tile-name { font-size: 40px; line-height: 0.9; }
.t-narrow .tile-meta { font-size: 12px; white-space: nowrap; align-self: center; }

/* Motion a game's tile art may use (see CREATING_GAMES.md). */
@keyframes tile-drain { from { width: 100%; } to { width: 0; } }
@keyframes tile-spin { to { transform: rotate(360deg); } }
@keyframes tile-bob { from { transform: translateY(0); } to { transform: translateY(-5px); } }
@keyframes tile-sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes tile-blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes sheet-open { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Sheets over the wall: an opened game, the join form ---- */
#sheet {
    position: fixed;
    inset: 0;
    z-index: 20;
    overflow-y: auto;
    background: var(--p-bg);
    display: flex;
    flex-direction: column;
}
.strip {
    flex: none;
    min-height: 52px;
    box-sizing: border-box;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: var(--p-bg);
    color: var(--p-ink);
    font-family: 'IBM Plex Sans Hebrew', system-ui, sans-serif;
    font-size: 15px;
}
.strip button {
    min-height: 44px;
    padding: 0 6px;
    border: 0;
    background: none;
    color: var(--p-ink);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}
.strip .brand { color: var(--p-muted); font-weight: 500; }
.strip .code { font-weight: 600; letter-spacing: 2px; direction: ltr; }

.sheet-body {
    flex: 1;
    width: 100%;
    max-width: 480px;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 0 8px 8px;
    display: flex;
    flex-direction: column;
}
.detail {
    flex: 1;
    box-sizing: border-box;
    padding: 26px 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transform-origin: 50% 30%;
    animation: sheet-open 0.28s ease-out;
}
.detail.shape-sharp { box-shadow: inset 0 0 0 5px var(--g-accent); }
.detail.shape-soft { border-radius: 14px; box-shadow: inset 0 0 0 5px var(--g-bg), inset 0 0 0 7px var(--g-accent); }
.detail.shape-round { border-radius: 28px; box-shadow: inset 0 0 0 3px var(--g-ink); }
.g-title { font-family: var(--g-display); font-weight: 700; line-height: 0.9; color: var(--g-name); overflow-wrap: anywhere; }
.font-toy .g-title { font-weight: 600; line-height: 1; }
.detail .g-title { font-size: 50px; }
.detail.font-show .g-title { font-size: 120px; }
.detail .g-desc { margin: 0; font-size: 19px; line-height: 1.45; }
.facts { display: flex; flex-direction: column; gap: 9px; }
.fact { border-top: 2px solid var(--g-line); padding-top: 9px; display: flex; flex-direction: column; gap: 1px; }
.fact span:first-child { font-size: 14px; font-weight: 600; color: var(--g-muted); }
.font-serif .fact span:first-child { color: var(--g-accent); }
.fact span:last-child { font-size: 18px; font-weight: 500; line-height: 1.3; }
.grow { flex: 1; }

/* ---- Parts shared by an opened game and the room ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 15px; font-weight: 500; color: var(--g-muted); }
.font-serif .field > label, .font-serif .field > .label { color: var(--g-accent); }
.g-input {
    width: 100%;
    height: 54px;
    box-sizing: border-box;
    padding: 0 14px;
    background: var(--g-surface);
    color: var(--g-ink);
    border: 2px solid var(--g-line);
    border-radius: 0;
    font-size: 19px;
    font-weight: 600;
}
.shape-soft .g-input { border-radius: 8px; border-width: 1px; }
.shape-round .g-input { border-radius: 16px; border: 3px solid var(--g-ink); }
.g-btn {
    width: 100%;
    min-height: 64px;
    box-sizing: border-box;
    padding: 6px 14px;
    border: 0;
    border-radius: 0;
    background: var(--g-accent);
    color: var(--g-accent-ink);
    font-family: var(--g-display) !important;
    font-weight: 700;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.12s ease;
}
.g-btn:active { transform: scale(0.97); }
.font-show .g-btn { font-size: 40px; }
.shape-soft .g-btn { border-radius: 8px; }
.shape-round .g-btn { border-radius: 22px; border: 3px solid var(--g-ink); box-shadow: 0 6px 0 var(--g-ink); font-weight: 600; font-size: 26px; }
.g-btn:disabled { opacity: 0.5; cursor: default; font-family: var(--g-body) !important; font-size: 17px; font-weight: 600; }
.g-link { border: 0; background: none; padding: 10px 0; color: var(--g-ink); font-size: 16px; font-weight: 500; text-decoration: underline; cursor: pointer; align-self: flex-start; }
.seg { display: flex; gap: 6px; }
.seg button {
    flex: 1;
    min-width: 0;
    min-height: 52px;
    box-sizing: border-box;
    padding: 4px 6px;
    background: var(--g-surface);
    color: var(--g-ink);
    border: 2px solid var(--g-line);
    border-radius: 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
}
.font-show .seg button { font-family: var(--g-display) !important; font-weight: 700; font-size: 30px; line-height: 1; }
.shape-soft .seg button { border-radius: 6px; border-width: 1px; }
.shape-round .seg button { border-radius: 14px; border: 3px solid var(--g-ink); }
.seg button[aria-pressed="true"] { background: var(--g-accent); color: var(--g-accent-ink); border-color: var(--g-accent); }
.shape-round .seg button[aria-pressed="true"] { border-color: var(--g-ink); }
.seg button:disabled { opacity: 0.45; cursor: default; }
.seg small { display: block; font-family: var(--g-body); font-size: 12px; font-weight: 500; }

/* ---- The room ---- */
#room { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.room-body {
    flex: 1;
    box-sizing: border-box;
    padding: 20px 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.room-body > * { width: 100%; max-width: 520px; margin-inline: auto; box-sizing: border-box; }
.room-head { display: flex; flex-direction: column; gap: 6px; }
.room-head p { margin: 0; font-size: 16px; line-height: 1.4; color: var(--g-muted); }
.room-head .g-title { font-size: 46px; }
.font-show .room-head .g-title { font-size: 104px; line-height: 0.82; }
.room-summary { font-size: 16px; color: var(--g-muted); line-height: 1.5; }

.invite {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px;
    background: var(--g-surface);
    border: 2px solid var(--g-line);
}
.shape-soft .invite { border-radius: 10px; border-width: 1px; }
.shape-round .invite { border-radius: 22px; border: 3px solid var(--g-ink); }
.invite img { width: 124px; height: 124px; flex: none; background: #FFFFFF; padding: 6px; box-sizing: border-box; border-radius: 6px; }
.invite-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.invite-text > span { font-size: 15px; color: var(--g-muted); }
.invite-code { font-family: 'IBM Plex Sans Hebrew', system-ui, sans-serif; font-size: 34px; font-weight: 600; letter-spacing: 3px; line-height: 1.1; direction: ltr; text-align: end; }
.invite .g-link { align-self: stretch; text-align: start; padding: 6px 0; }

.settings { display: flex; flex-direction: column; gap: 14px; }
.readonly { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.readonly > div { border: 2px solid var(--g-line); padding: 8px 12px; display: flex; flex-direction: column; min-width: 0; }
.shape-soft .readonly > div { border-radius: 8px; border-width: 1px; }
.shape-round .readonly > div { border-radius: 16px; border: 3px solid var(--g-ink); background: var(--g-surface); }
.readonly span:first-child { font-size: 14px; color: var(--g-muted); }
.readonly span:last-child { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 500; }
.toggle input { width: 22px; height: 22px; accent-color: var(--g-accent); }

.members { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.slate {
    min-height: 64px;
    box-sizing: border-box;
    padding: 8px 12px;
    background: var(--g-surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}
.shape-sharp .slate { border-top: 5px solid var(--g-accent); }
.shape-soft .slate { border-radius: 6px; border: 1px solid var(--g-line); }
.shape-round .slate { border-radius: 16px; border: 3px solid var(--g-ink); }
.slate.away { opacity: 0.5; }
.slate.empty { background: none; border: 2px dashed var(--g-line); color: var(--g-muted); font-size: 15px; }
.shape-round .slate.empty { border: 3px dashed var(--g-ink); }
.slate-name { font-family: var(--g-display); font-weight: 700; font-size: 22px; line-height: 1.05; overflow-wrap: anywhere; }
.font-show .slate-name { font-size: 40px; line-height: 0.9; }
.font-toy .slate-name { font-weight: 600; }
.slate-tag { font-size: 13px; color: var(--g-muted); }
.font-serif .slate-tag { color: var(--g-accent); }

.teams { display: flex; flex-direction: column; gap: 8px; }
.team-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; background: var(--g-surface); border: 3px solid var(--g-ink); border-radius: 16px; font-size: 17px; font-weight: 500; }
.team-row[data-team="0"] { box-shadow: inset -8px 0 0 #4D7CFE; }
.team-row[data-team="1"] { box-shadow: inset -8px 0 0 #E5484D; }
.team-row select { height: 40px; border: 2px solid var(--g-ink); border-radius: 10px; background: #FFFFFF; color: #15151A; font-size: 16px; padding: 0 8px; }

.room-foot { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.room-wait { margin: 0; font-size: 17px; text-align: center; color: var(--g-muted); }

/* The room on a shared screen: one glance from across the room. */
@media (min-width: 900px) {
    .room.is-screen .room-body {
        padding: 4vh 4vw 5vh;
        display: grid;
        grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
        grid-template-rows: 1fr auto auto;
        grid-template-areas: "head invite" "members members" "foot foot";
        align-items: center;
        gap: 3vh 4vw;
    }
    .room.is-screen .room-body > * { max-width: none; }
    .room.is-screen .room-head { grid-area: head; gap: 2vh; }
    .room.is-screen .room-head .g-title { font-size: clamp(64px, 7vw, 120px); }
    .room.is-screen.font-show .room-head .g-title { font-size: clamp(140px, 18vw, 300px); line-height: 0.78; }
    .room.is-screen .room-head p, .room.is-screen .room-summary { font-size: clamp(18px, 1.9vw, 30px); }
    .room.is-screen .invite { grid-area: invite; border: 0; background: none; padding: 0; gap: 2vw; justify-content: flex-end; }
    .room.is-screen .invite img { width: clamp(180px, 18vw, 300px); height: clamp(180px, 18vw, 300px); padding: 12px; border-radius: 0; }
    .room.is-screen .invite-text { flex: none; }
    .room.is-screen .invite-text > span { font-size: clamp(18px, 1.7vw, 26px); color: var(--g-ink); }
    .room.is-screen .invite-code { font-size: clamp(56px, 6.4vw, 110px); letter-spacing: 0.06em; }
    .room.is-screen .invite .g-link { display: none; }
    .room.is-screen .members { grid-area: members; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; }
    .room.is-screen .slate { min-height: clamp(84px, 13vh, 130px); justify-content: space-between; padding: 10px 14px; }
    .room.is-screen .slate-name { font-size: clamp(22px, 2.2vw, 34px); }
    .room.is-screen.font-show .slate-name { font-size: clamp(36px, 4.2vw, 62px); }
    .room.is-screen .room-foot { grid-area: foot; margin: 0; }
    .room.is-screen .room-wait { text-align: start; font-family: var(--g-display); font-weight: 700; font-size: clamp(22px, 2.4vw, 40px); color: var(--g-ink); }
    .room.is-screen.font-show .room-wait { font-size: clamp(30px, 3.4vw, 54px); }
}

/* ---- Small things ---- */
.toast {
    position: fixed;
    inset-inline: 12px;
    bottom: 16px;
    z-index: 40;
    max-width: 456px;
    margin: 0 auto;
    padding: 12px 16px;
    border-radius: 14px;
    background: #FFFFFF;
    color: #0F1022;
    font-family: 'IBM Plex Sans Hebrew', system-ui, sans-serif;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
#google-button { min-height: 44px; }

@media (prefers-reduced-motion: reduce) {
    #shell *, #shell *::before, #shell *::after { animation: none !important; transition: none !important; }
}
