@font-face {
    font-family: 'DM Sans';
    src: url('fonts/dm-sans.woff2') format('woff2');
    font-weight: 400 700;
    font-display: swap;
}

@font-face {
    font-family: 'Instrument Serif';
    src: url('fonts/instrument-serif.woff2') format('woff2');
    font-display: swap;
}

@font-face {
    font-family: 'Instrument Serif';
    src: url('fonts/instrument-serif-italic.woff2') format('woff2');
    font-style: italic;
    font-display: swap;
}

:root {
    color-scheme: dark;
    --ink: #f4ecda;
    --muted: #a6b5a8;
    --gold: #dfbe82;
    --line: #2d4436;
    --paper: #10251a;
    font-family: 'DM Sans', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: radial-gradient(ellipse at 64% 28%, #172a1d 0, #0a1c13 46%, #07140d 100%);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
input:focus-visible, button:focus-visible { outline: 2px solid #efcb8b; outline-offset: 4px; }
button:disabled:focus-visible { outline-offset: 1px; }
h1, h2, p { margin: 0; }
.shell { width: min(1392px, 100%); margin: auto; padding: 0 clamp(22px, 4vw, 66px) 36px; }

.topbar {
    display: flex;
    height: 82px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #38504288;
    margin-bottom: clamp(22px, 4vw, 54px);
}

.brand { display: inline-flex; align-items: center; gap: 13px; font-size: 17px; letter-spacing: -.025em; font-weight: 700; }
.brand-mark {
    width: 17px; height: 27px; transform: rotate(-18deg); border-radius: 4px;
    background: #e8cb94; box-shadow: 0 2px 0 #86633a, 4px 5px 9px #02130999;
    position: relative;
}
.brand-mark::after { content: ''; position: absolute; inset: 50% 2px auto; border-top: 1px solid #70543385; }
.brand-mark i { position: absolute; width: 3px; height: 3px; background: #193021; border-radius: 50%; }
.brand-mark i:nth-child(1) { left: 7px; top: 5px; }
.brand-mark i:nth-child(2) { left: 4px; top: 17px; }
.brand-mark i:nth-child(3) { left: 10px; top: 22px; }
.text-button {
    border: 0; background: none; color: #d4e0d5; min-height: 40px; padding: 6px 5px;
    font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px;
}
.text-button:hover { color: #fff5df; }
.help-icon { width: 18px; height: 18px; border: 1px solid #88a193; border-radius: 50%; display: grid; place-items: center; font-size: 11px; }
.overline { color: var(--gold); text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: .17em; }
.lobby { display: grid; grid-template-columns: minmax(252px, 350px) minmax(0, 1fr); column-gap: clamp(30px, 6vw, 94px); align-items: center; }
.entry { max-width: 350px; }
.entry h1 {
    margin: 11px 0 16px; color: #f7eedb; font-family: 'Instrument Serif', Georgia, serif;
    font-size: clamp(68px, 7.2vw, 108px); line-height: .85; letter-spacing: -.037em; font-weight: 400;
}
.entry h1 em { color: var(--gold); font-weight: 400; }
.entry-caption { max-width: 32ch; color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 26px; }
.mode-switch, .capacity { display: grid; gap: 5px; background: #091b12; border: 1px solid var(--line); border-radius: 11px; padding: 4px; }
.mode-switch { grid-template-columns: 1fr 1.23fr; margin-bottom: 21px; }
.capacity { grid-template-columns: repeat(3, 1fr); width: 170px; }
.mode-switch button, .capacity button {
    border: 1px solid transparent; color: #b6c7ba; background: transparent; border-radius: 7px;
    min-height: 39px; padding: 5px 9px; font-size: 13px; font-weight: 700;
}
.mode-switch button[aria-pressed="true"], .capacity button[aria-pressed="true"] {
    color: #f7eedb; border-color: #3a5847; background: #21382a; box-shadow: 0 2px 4px #0003;
}
.mode-switch button:hover, .capacity button:hover { color: #fff4de; }
label, .field-label { display: block; color: #e1e8dc; font-size: 13px; font-weight: 700; margin: 0 0 8px; }
input {
    width: 100%; color: var(--ink); background: #0c2015; border: 1px solid #3a5746;
    min-height: 48px; padding: 11px 13px; border-radius: 10px; font-size: 15px;
}
input::placeholder { color: #90a398; opacity: 1; }
#room-input { font-family: 'DM Sans', sans-serif; font-weight: 700; letter-spacing: .24em; text-transform: uppercase; }
#create-fields, #join-fields { margin-top: 15px; }

.gold-button, .outline-button {
    border-radius: 10px; min-height: 42px; font-size: 13px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.gold-button {
    color: #261a0d; border: 1px solid #efcf92; padding: 9px 16px;
    background: linear-gradient(145deg, #f4d8a1, #d3a963);
    box-shadow: inset 0 1px #fff7d5a6, 0 3px 0 #8e684132, 0 8px 19px #07150d66;
}
.gold-button:hover:not(:disabled) { background: linear-gradient(145deg, #ffe4b2, #e3bc75); }
.gold-button:disabled { opacity: .48; }
.enter-button { width: 100%; min-height: 51px; justify-content: space-between; margin-top: 20px; font-size: 15px; padding-inline: 15px; }
.arrow-icon { position: relative; flex: none; width: 9px; height: 9px; border-top: 1.5px solid; border-right: 1.5px solid; }
.arrow-icon::after { content: ''; position: absolute; width: 11px; height: 1.5px; top: 3px; right: -2px; transform: rotate(-45deg); background: currentColor; }
.outline-button { color: #e5e8d9; border: 1px solid #577362; background: #12281c; padding: 7px 12px; }
.outline-button:hover { color: #fff3d6; border-color: #b09262; }
.form-message, .notice { color: #ffd195; font-size: 13px; line-height: 1.4; }
.form-message { margin-top: 11px; }
.notice { margin: 0 0 9px; min-height: 1.4em; }

.wood {
    background:
        repeating-linear-gradient(93deg, #5229092e 0 2px, transparent 2px 6px, #e1a66e20 6px 7px, transparent 7px 17px),
        repeating-linear-gradient(6deg, #1e10092b 0 1px, transparent 1px 11px, #c9975b18 11px 13px, transparent 13px 23px),
        linear-gradient(137deg, #835535 4%, #4d2e1c 33%, #7a4c2c 72%, #392315);
}
.felt {
    background-color: #21563c;
    background-image: radial-gradient(ellipse at 38% 33%, #26574025 22%, #0b1f16a6 95%), url('felt.webp');
    background-size: cover;
    background-position: center;
}
.showcase {
    min-width: 0;
    position: relative;
    isolation: isolate;
    height: clamp(460px, 47vw, 665px);
    display: grid;
    place-items: center;
    perspective: 1200px;
}
.showcase::before {
    content: ''; position: absolute; z-index: -2; inset: 5% -4% 9%;
    background: radial-gradient(ellipse at 51% 48%, #53754e5c 0, transparent 67%);
}
.showcase-table {
    position: relative; width: 96%; height: 91%; border-radius: 51px; padding: clamp(19px, 2.75vw, 37px);
    border: 1px solid #b88b58; transform: rotateX(12deg) rotateZ(-7deg) translateY(-7px);
    box-shadow: inset 0 0 0 3px #ecc6903d, inset 0 -4px 12px #2b1b0d, 0 13px 0 #392317, 0 20px 0 #2a1b11, 0 37px 48px #020a06d9;
}
.showcase-table::after {
    content: ''; position: absolute; z-index: -1; inset: 8px; border: 1px solid #d2a37252; border-radius: 43px;
}
.showcase-felt {
    position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: 31px;
    border: 1px solid #151b10; box-shadow: inset 0 0 23px 4px #101d11c9, 0 1px 0 #b9925e6e;
}
.showcase-inlay, .inlay {
    pointer-events: none; position: absolute; inset: 15px; border-radius: 20px; border: 1px solid #d6c5925e;
    box-shadow: 0 0 0 4px #d6c59216, inset 0 0 0 3px #1a3d2480;
}
.showcase-pieces {
    display: flex; position: absolute; top: 47%; left: 50%; transform: translate(-50%, -50%) rotate(12deg);
    align-items: center; justify-content: center; gap: clamp(3px, .4vw, 7px); width: max-content;
}
.showcase-pieces .domino { width: clamp(54px, 8vw, 114px); height: auto; aspect-ratio: 2.04; }
.showcase-pieces .domino:nth-child(2) { transform: translateY(2px) rotate(-3deg); }
.showcase-pieces .domino:nth-child(3) { transform: translateY(-1px) rotate(3deg); }
.showcase-pieces .domino:nth-child(4) { transform: translateY(1px) rotate(-2deg); }
.showcase-rack {
    position: absolute; z-index: 2; right: 6%; bottom: 8%; padding: 10px 14px 13px; border-radius: 12px;
    transform: rotate(-9deg) rotateX(8deg); border: 1px solid #bd9362;
    box-shadow: inset 0 1px #ecc4977a, 0 8px 0 #3c2518, 0 13px 20px #061109ae;
}
#showcase-hand { display: flex; align-items: end; gap: 4px; }
#showcase-hand .domino { width: clamp(26px, 3.6vw, 49px); height: auto; aspect-ratio: .505; }
#showcase-hand .domino:nth-child(2) { transform: rotate(-4deg) translateY(-3px); }
#showcase-hand .domino:nth-child(4) { transform: rotate(3deg) translateY(-2px); }

.domino {
    --rim: #ab9064;
    position: relative; display: grid; flex: none; grid-template-rows: 1fr 1fr; width: 52px; height: 103px;
    color: #172620; background: linear-gradient(144deg, #fff4d8 0%, #e9dbc0 88%);
    padding: 0; border: 1px solid #ffedc6; border-radius: 7px;
    box-shadow: inset 0 1px #fff6dc, inset 0 -1px #af977979, 0 4px 0 var(--rim), 0 7px 0 #695138, 0 10px 13px #07150fb0;
    user-select: none; flex-shrink: 0;
}
.domino.is-flat { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.domino::after { content: ''; position: absolute; top: 50%; left: 5px; right: 5px; height: 1px; background: #80694f8f; box-shadow: 0 1px #fff4d6af; }
.domino.is-flat::after { inset: 4px auto 4px 50%; width: 1px; height: auto; }
.half { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); padding: 13%; grid-row: auto; place-items: center; min-width: 0; min-height: 0; }
.pip { width: 63%; max-height: 100%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 32% 68%, #24382c, #121d16 62%); box-shadow: 0 1px #fff7dc, inset 0 1px 2px #000a; }
.domino[aria-pressed="true"] { outline: 2px solid #edc478; outline-offset: 3px; transform: translateY(-6px); }
button.domino:not(:disabled):hover { transform: translateY(-6px); filter: brightness(1.075); }

.room { max-width: 1260px; margin-inline: auto; }
.roombar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.room-heading { display: flex; align-items: center; gap: 13px; flex-wrap: wrap; }
#room-code { color: #fae7bd; font-size: 22px; letter-spacing: .14em; font-weight: 700; }
.share-button { font-size: 12px; min-height: 36px; }
.leave-button { flex-shrink: 0; }
.roombar + .notice { text-align: right; }
body.is-playing .topbar { margin-bottom: 20px; }
.arena { position: relative; display: grid; padding: 55px min(13%, 143px) 0; }

.table {
    position: relative; padding: clamp(9px, 1.4vw, 19px);
    border: 1px solid #ac784f; border-radius: 30px; min-width: 0;
    box-shadow: inset 0 0 0 2px #d9a56e62, inset 0 -6px 10px #33211480, 0 7px 0 #312215, 0 14px 24px #020a05a6;
}
.playmat {
    position: relative; display: flex; flex-direction: column; align-items: stretch; isolation: isolate;
    height: clamp(350px, 47vh, 590px); overflow: hidden; border-radius: 19px; padding: 20px 27px;
    border: 1px solid #201a0c; box-shadow: inset 0 3px 15px #07120ac4, inset 0 0 19px #05180fe6;
}
.playmat .inlay { inset: 8px; border-radius: 15px; z-index: -1; }
.table-hud { display: flex; flex: 0 0 auto; justify-content: space-between; gap: 10px; font-weight: 700; font-size: 12px; color: #ead6b0; line-height: 1.3; }
.board-space { position: relative; display: grid; flex: 1 1 auto; width: 100%; min-height: 0; place-items: center; }
.last-move { max-width: 100%; overflow-wrap: anywhere; min-height: 16px; text-align: center; color: #edf2de; font-size: 12px; line-height: 1.3; text-shadow: 0 1px 3px #05140c; }
.chain { display: grid; align-items: center; justify-items: center; gap: 14px 3px; }
.chain .domino { width: var(--tile-width); height: calc(var(--tile-width) / 2.04); border-radius: clamp(3px, .5vw, 7px); }
.chain .domino.is-new { animation: drop-in .22s ease-out both; }
@keyframes drop-in {
    from { opacity: .4; transform: translateY(-5px) scale(1.04); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.endpoint {
    display: flex; align-items: center; justify-content: center; gap: 3px; width: 100%;
    min-width: 20px; height: calc(var(--tile-width) / 2.05);
    border: 1px solid #eee2bc75; border-radius: 6px; background: #0c2c1baf; color: #f2e5bc;
    font-size: clamp(10px, 1.2vw, 13px); font-weight: 700;
}
button.endpoint { background: #ead39c; color: #221b0e; border-color: #fff2be; }
button.endpoint:hover { background: #f7e1a9; }
.chain-turn {
    width: 4px; height: 14px; margin-top: 4px; align-self: end; transform: translateY(13px);
    color: #c9b783d4; border-radius: 4px; background: repeating-linear-gradient(to bottom, currentColor 0 2px, transparent 2px 4px); pointer-events: none;
}
.seats { display: contents; }
.seat {
    position: absolute; z-index: 2; width: min(122px, 13%); padding: 9px 7px 10px; text-align: center; min-width: 0;
    border: 1px solid #344e3d; background: #102518; border-radius: 13px; color: #dbebdb;
}
.seat.is-turn { border-color: #deba77; box-shadow: 0 0 0 3px #bd93562e; }
.seat.is-empty { background: #0b1d136b; color: #92a698; border-style: dashed; }
.seat-top { top: 0; left: 50%; transform: translateX(-50%); }
.seat-left { left: 0; top: 55%; transform: translateY(-50%); }
.seat-right { right: 0; top: 55%; transform: translateY(-50%); }
.seat-header { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 5px; }
.seat-avatar {
    display: grid; place-items: center; border-radius: 7px; background: #254735;
    width: 23px; height: 23px; font-weight: 700; font-size: 11px; color: #efdaaf;
}
.seat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; text-align: left; }
.seat-count { display: block; margin-top: 4px; color: #aabdaf; font-size: 11px; }
.mini-stack { display: flex; justify-content: center; margin-top: 6px; height: 15px; }
.mini-stack i {
    display: block; width: 10px; height: 15px; margin-left: -2px; border: 1px solid #d8b779;
    border-radius: 2px; background: repeating-linear-gradient(60deg, #172a1f 0 1px, #344c38 1px 3px);
    box-shadow: 0 1px #8c6437; transform: rotate(-8deg);
}

.table-overlay {
    width: min(100%, 340px); grid-area: 1 / 1; z-index: 2; text-align: center;
    padding: 13px 10px; color: #fff1d2; text-shadow: 0 2px 9px #0d2417;
}
.table-overlay[hidden] { display: none; }
.table-overlay h2 { font: 400 clamp(39px, 6vw, 62px)/.95 'Instrument Serif', Georgia, serif; overflow-wrap: anywhere; }
.table-overlay p { color: #e0e6d5; font-size: 13px; line-height: 1.4; margin: 9px auto 13px; max-width: 30ch; }
.table-overlay .gold-button { text-shadow: none; }
.board-space.show-result .chain { opacity: .24; }
.chain { grid-area: 1 / 1; }
.result-list { list-style: none; max-width: 205px; margin: 0 auto 12px; padding: 0; overflow: auto; }
.result-list li {
    display: flex; justify-content: space-between; gap: 9px; padding: 3px 1px;
    border-bottom: 1px solid #ddd0aa3e; font-size: 12px; color: #e4e7d4;
}
.result-list span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-list span:last-child { flex: 0 0 auto; }

.hand-dock {
    display: grid; grid-template-columns: minmax(105px, 1fr) minmax(0, 8fr) minmax(108px, 1.1fr);
    align-items: center; gap: 16px; background: #102319; border: 1px solid #395444; border-radius: 16px;
    margin: 24px auto 0; min-height: 142px; padding: 10px 16px 8px; width: min(100%, 1070px);
}
.hand-title { display: grid; gap: 5px; }
.hand-title strong, .hand-title span { overflow-wrap: anywhere; }
.hand-title strong { font-size: 14px; }
.hand-title span, .hand-actions p { font-size: 12px; color: #b8cbbd; line-height: 1.4; }
.hand-rack { display: flex; flex-wrap: wrap; align-items: center; align-content: center; gap: 15px 7px; min-height: 115px; min-width: 0; padding: 12px 5px 14px; }
.hand-rack .domino { width: clamp(31px, 4.2vw, 51px); height: auto; aspect-ratio: .505; transition: transform .15s, filter .15s; }
.hand-rack .domino:disabled { opacity: .76; }
.hand-rack .domino.is-legal { --rim: #af955e; border-color: #ffeeba; }
.hand-actions { display: flex; flex-direction: column; align-items: start; justify-content: center; gap: 6px; }
.hand-actions .gold-button { min-height: 34px; padding: 5px 9px; }

dialog {
    width: min(480px, calc(100% - 32px)); border: 1px solid #59715f; border-radius: 15px; background: #142c1e;
    padding: 22px; color: #f4ecda; box-shadow: 0 20px 65px #021007b3;
}
dialog::backdrop { background: #040d09bc; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dialog-heading h2 { font-family: 'Instrument Serif', Georgia, serif; font-size: 39px; line-height: 1; font-weight: 400; }
.icon-button { min-width: 38px; padding: 6px; }
dialog ol { padding-left: 21px; font-size: 14px; }
dialog li, dialog p { color: #e0e7d9; line-height: 1.5; margin: 11px 0; }

@media (max-width: 950px) {
    .lobby { gap: 30px; grid-template-columns: minmax(245px, 300px) minmax(0, 1fr); }
    .showcase { height: clamp(370px, 58vw, 570px); }
    .showcase-table { width: 96%; height: 83%; border-radius: 35px; }
    .showcase-table::after { border-radius: 28px; }
    .showcase-felt { border-radius: 20px; }
    .arena { padding-inline: 13.5%; }
    .seat { width: 13%; }
}
@media (max-width: 690px) {
    .shell { padding-inline: 14px; padding-bottom: 18px; }
    .topbar { height: 62px; margin-bottom: 22px; }
    .lobby { display: flex; flex-direction: column; gap: 20px; }
    .entry { width: min(100%, 385px); order: 2; }
    .entry h1 { font-size: clamp(52px, 11vw, 82px); margin: 7px 0 9px; }
    .entry h1 br { display: none; }
    .entry-caption { max-width: none; margin-bottom: 16px; }
    .mode-switch { margin-bottom: 12px; }
    .showcase { order: 1; width: min(100%, 420px); height: clamp(182px, 51vw, 350px); margin-top: -6px; }
    .showcase-table { border-radius: 24px; height: 90%; padding: 13px; }
    .showcase-table::after { border-radius: 20px; inset: 5px; }
    .showcase-felt { border-radius: 12px; }
    .showcase-inlay { inset: 8px; border-radius: 9px; }
    .showcase-pieces .domino { width: clamp(49px, 12vw, 80px); border-radius: 5px; }
    .showcase-rack { bottom: 4%; right: 8%; padding: 5px 7px 8px; }
    #showcase-hand .domino { width: clamp(21px, 6vw, 33px); border-radius: 4px; }
    body.is-playing .topbar { margin-bottom: 11px; }
    .roombar { margin-bottom: 9px; }
    .room-heading { gap: 6px 9px; }
    #room-code { font-size: 16px; letter-spacing: .1em; }
    .share-button, .leave-button { font-size: 11px; }
    .share-button { padding-inline: 6px; }
    .arena { padding: 0; gap: 7px; }
    .seats { display: flex; justify-content: center; align-items: stretch; gap: 6px; }
    .seat { position: static; transform: none; min-width: 0; width: min(31%, 142px); padding: 5px; }
    .seat-count { font-size: 10px; }
    .mini-stack { display: none; }
    .table { padding: 6px; border-radius: 15px; }
    .playmat { padding: 11px 11px 13px; height: clamp(310px, 46vh, 500px); border-radius: 10px; }
    .playmat .inlay { inset: 4px; border-radius: 8px; }
    .table-hud, .last-move { font-size: 10px; }
    .hand-dock { margin-top: 15px; padding: 6px 8px; gap: 1px 8px; grid-template-columns: 1fr 1fr; }
    .hand-title { grid-column: 1; }
    .hand-rack { grid-column: 1 / -1; grid-row: 2; min-height: 91px; column-gap: 5px; }
    .hand-actions { grid-column: 2; grid-row: 1; justify-self: end; align-items: end; text-align: right; }
    .hand-actions .gold-button { font-size: 11px; }
    .chain { gap: 12px 3px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
