:root {
    color-scheme: dark;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
    color: #f4edd9;
    background: #101b23;
    -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #ffe1a0; outline-offset: 3px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.game-shell { max-width: 450px; margin: auto; padding: 4px 4px max(10px, env(safe-area-inset-bottom)); background: radial-gradient(ellipse at 50% 0, #223b37, #101b23 65%); }
.icon-button { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; padding: 0; border: 1px solid #b89a5155; border-radius: 12px; color: #dbc58b; background: #ffffff06; font-size: 16px; }
.table { overflow: hidden; border: 1px solid #c9a452; border-radius: 22px; background: #12252b; box-shadow: inset 0 0 0 2px #ffe4a01c, 0 3px 0 #6a522c, 0 12px 28px #0003; }
.arena {
    position: relative;
    isolation: isolate;
    padding: 20px 12px 4px;
    color: #fff8df;
    background:
        radial-gradient(ellipse at 50% 0, #d5bd6433, transparent 55%),
        repeating-linear-gradient(112deg, #ffffff03 0 1px, transparent 1px 4px),
        radial-gradient(ellipse at 50% 40%, #226957, #0a342e 95%);
    border-bottom: 3px solid;
    border-image: linear-gradient(90deg, #5d4522, #d3aa57 24%, #fff1bd 50%, #d3aa57 76%, #5d4522) 1;
}
.arena::before { content: ""; pointer-events: none; position: absolute; z-index: -1; inset: 8px 8px 12px; border: 1px solid #e3c77238; border-radius: 17px 17px 45% 45% / 17px 17px 16% 16%; box-shadow: inset 0 0 25px #0002; }
.opponents { display: flex; justify-content: space-around; gap: 8px; min-height: 125px; }
.opponent { position: relative; width: 30%; text-align: center; padding-top: 14px; }
.opponent:nth-child(2) { padding-top: 0; }
.portrait { position: relative; width: 72px; height: 72px; margin: auto; border-radius: 50%; background: radial-gradient(circle at 45% 35%, #fff6d9, #d4c298); border: 3px solid #c8ae6d; box-shadow: 0 0 0 3px #102b287d, inset 0 0 0 1px #fff7d8, 0 5px 13px #021c1d66; }
.portrait img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; filter: drop-shadow(0 2px 1px #3b241625); }
.opponent.is-turn .portrait { border-color: #ffe5a2; box-shadow: 0 0 0 4px #ffdc6e25, 0 0 23px #ffd37555, 0 4px 14px #092c274d; }
.opponent.is-turn .portrait::before { content: ""; position: absolute; left: calc(50% - 4px); bottom: -13px; width: 8px; height: 5px; background: #ffe5a2; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.opponent.is-finished .portrait { border-color: #f3d38a; box-shadow: 0 0 0 3px #f3d38a20, 0 5px 13px #021c1d66; }
.opponent-name { display: block; font-size: 11px; margin-top: 10px; color: #f7efd6; text-shadow: 0 1px 3px #062922; }
.remaining { position: absolute; right: -7px; bottom: -2px; display: grid; place-items: center; min-width: 25px; height: 24px; padding: 0 5px; border: 1px solid #d0b271; border-radius: 8px; color: #fff4d1; background: linear-gradient(#2c493f, #142e2b); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; box-shadow: 0 2px 4px #001c1e55; }
.is-finished .remaining { background: linear-gradient(#ffe5a2, #c39640); color: #3c2a14; }
.bubble { height: 32px; margin-top: 4px; font-size: 11px; line-height: 16px; color: #f7dfab; overflow-wrap: anywhere; text-shadow: 0 1px 3px #052c24; }
.pass-marker { position: absolute; top: -3px; left: -10px; padding: 2px 5px; border-radius: 7px; background: #162c2d; border: 1px solid #839d8b; color: #d6dfce; font-size: 9px; line-height: 13px; }
.table-center { display: flex; align-items: center; justify-content: center; flex-direction: column; position: relative; min-height: 185px; padding: 12px 0 8px; }
.table-center::before { content: ""; position: absolute; z-index: -1; inset: 28px 8px 24px; border: 1px solid #e5cb7c30; border-radius: 50%; background: radial-gradient(ellipse, #accc9b0a, transparent 70%); box-shadow: 0 0 0 6px #092e261c, inset 0 0 22px #001d221a; }
#status { margin: 0 0 13px; padding: 4px 12px; border: 1px solid #e3d49b26; border-radius: 20px; font-size: 12px; font-weight: 650; min-height: 24px; color: #e8ebd7; background: #072c2845; letter-spacing: .02em; }
.is-player-turn #status { border-color: #e3c5777a; color: #ffebb1; background: #102e28c9; box-shadow: 0 0 15px #d7b75818; }
.pile { display: flex; gap: 6px; align-items: center; justify-content: center; min-height: 84px; }
.table-mark { color: #f3dc9938; font: 30px/1 Georgia, serif; letter-spacing: .18em; text-shadow: 0 1px #0002; }
.event { min-height: 20px; margin: 12px 0 0; font-size: 12px; font-weight: 750; color: #ffe3a1; }
.event:not(:empty) { text-shadow: 0 0 12px #ffc95788; }
.revolution { position: absolute; top: -13px; background: linear-gradient(120deg, #6b204d, #3e2142); color: #ffdf95; border: 1px solid #e3b85c; border-radius: 20px; padding: 5px 12px; font-size: 11px; font-weight: 800; box-shadow: 0 0 18px #e66da840, inset 0 1px #ffffff1c; }
.is-revolution .arena { background: radial-gradient(ellipse at 50% 40%, #514451, #182e31 95%); }
.card { position: relative; display: block; overflow: hidden; color: #20353d; background: linear-gradient(135deg, #fffef8, #f5efd9); border-radius: 7px; border: 1px solid #dfd4b3; box-shadow: 0 2px 0 #b5a879, 0 4px 7px #001e2940; padding: 0; text-align: left; font: 700 20px/1 Georgia, serif; }
.card.red { color: #b52e4f; }
.card-rank { position: absolute; top: 5px; left: 5px; letter-spacing: -.06em; }
.card .suit { position: absolute; top: 25px; left: 5px; font-size: 13px; }
.card::before { content: attr(data-suit); position: absolute; right: 5px; bottom: 15px; font-size: 27px; font-weight: 400; }
.card::after { content: attr(data-rank); position: absolute; right: 4px; bottom: 4px; font-size: 11px; transform: rotate(180deg); }
.pile .card { width: 58px; height: 84px; transform: rotate(-5deg); box-shadow: 0 3px 0 #ad9d6d, 0 7px 12px #001b2380; }
.pile .card:nth-child(even) { transform: rotate(5deg) translateY(-3px); }
.pile .card::before { right: 9px; bottom: 19px; font-size: 33px; }
.player-area { position: relative; padding: 7px 10px 12px; background: radial-gradient(ellipse at 50% 0, #334d422e, transparent 80%), linear-gradient(#192e30, #101e28); box-shadow: inset 0 1px #fff2; }
.player-label { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin: 0 1px 6px; min-height: 44px; color: #a9b8ac; font-size: 11px; }
.player-meta { display: flex; gap: 6px; align-items: center; }
#you { display: inline-flex; align-items: center; gap: 6px; font-weight: 750; }
#you::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #61756d; }
#you.is-turn { color: #ffdf94; }
#you.is-turn::before { background: #f1c568; box-shadow: 0 0 0 3px #f1c56820, 0 0 10px #ffdc89a0; }
#hand-count { padding: 5px 9px; border: 1px solid #d3bb7730; border-radius: 20px; background: #c6b06c13; color: #ddc990; font-size: 10px; font-weight: 750; font-variant-numeric: tabular-nums; }
#hand-count:empty { visibility: hidden; }
#table-choice { max-width: 155px; min-height: 44px; padding: 6px 8px; border: 1px solid #d3bb7770; border-radius: 12px; color: #f5d999; background: #192e30; font: inherit; font-size: 12px; }
#table-choice:focus-visible { outline: 3px solid #ffe1a0; outline-offset: 2px; }
.table-change { width: 100%; min-height: 44px; margin-top: 12px; border: 1px solid #d3bb7770; border-radius: 12px; color: #f5d999; background: #192e30; font-size: 13px; }
.hand { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 11px 5px; min-height: 163px; align-content: start; padding-top: 6px; }
.hand .card { width: 100%; height: 73px; }
.hand .card.playable { border-color: #d8c17e; box-shadow: 0 2px 0 #a18b58, 0 0 6px #f0cf6c10; }
.hand .card:disabled { background: #d1d6cb; color: #62726a; border-color: #a7b2a3; box-shadow: 0 2px 0 #8c9a8c; }
.hand .card.red:disabled { color: #955f6a; }
.hand .card.selected { transform: translateY(-7px); border-color: #fff1b6; background: linear-gradient(145deg, #fffef4, #ffe5a0); box-shadow: 0 0 0 2px #e3b958, 0 0 18px #edbf4f55, 0 6px 10px #0004; }
.controls { display: grid; grid-template-columns: 1fr 1.65fr; gap: 9px; margin-top: 12px; }
.controls.is-spectating { grid-template-columns: 1fr; }
.controls button, .primary { min-height: 48px; border-radius: 13px; padding: 10px 17px; font-size: 14px; font-weight: 750; border: 1px solid transparent; }
.controls button { color: #ddd9c3; background: linear-gradient(#2c4140, #1a2c30); border-color: #73867566; box-shadow: 0 2px 0 #0a1921; }
button.primary { color: #392a16; background: linear-gradient(120deg, #b98a3b, #ffe8a6 44%, #e4b95f 75%, #c39443); border: 1px solid #ffe5a6; box-shadow: 0 3px 0 #7e5928, 0 0 18px #e7b75322, inset 0 1px #fff6d9; text-shadow: 0 1px #fff3; }
.controls button:disabled, .controls button.primary:disabled { color: #7c8d84; background: #263738; border-color: #41544d; box-shadow: none; text-shadow: none; }
.start-button { position: absolute; top: 97px; min-width: 174px; }
.table.is-idle .hand { min-height: 70px; }
.table.is-idle .hand::before { content: "♠"; justify-self: center; grid-column: 1 / -1; display: grid; place-items: center; width: 48px; height: 67px; border: 3px double #e6cd8f; border-radius: 6px; background: repeating-linear-gradient(45deg, #27493f 0 2px, #325749 2px 4px); color: #f6db98; font-size: 26px; transform: rotate(-9deg); box-shadow: 14px 2px 0 -1px #7d8d6b, 28px 5px 0 -2px #b9b17d, 0 0 20px #f0d77916; margin-left: -24px; }
.table.is-idle .controls { display: none; }
dialog { width: min(340px, calc(100% - 28px)); border: 1px solid #d5b36c; border-radius: 23px; padding: 24px; text-align: center; color: #efe6cf; background: radial-gradient(ellipse at 50% 0, #33463a, #15262e 70%); box-shadow: inset 0 0 0 4px #c7a76113, 0 20px 70px #0008; }
dialog::backdrop { background: #071719b3; backdrop-filter: blur(5px); }
dialog h2 { margin: 0 0 18px; font-size: 22px; letter-spacing: .03em; color: #f5d999; }
dialog p { font-size: 13px; line-height: 1.9; margin: 0 0 17px; }
dialog .rule-note { color: #a5b6a7; font-size: 11px; }
dialog .primary { width: 100%; }
.result-crown { display: block; width: 76px; height: 76px; line-height: 76px; margin: 0 auto 10px; border: 1px solid #c3a76b66; border-radius: 50%; background: radial-gradient(circle at 40% 25%, #e4c77c2e, #9a773f13); color: #e8ca80; font-size: 47px; }
#result.is-victory .result-crown { color: #ffedb5; border-color: #ffdf8c; background: radial-gradient(circle, #b7843b99, #7b632e16 72%); box-shadow: 0 0 0 5px #e5bd5f12, 0 0 35px #edbd534d; text-shadow: 0 0 14px #ffd16a; }
#result.is-victory { background: radial-gradient(ellipse at 50% 0, #75633a88, transparent 60%), #15262e; }
#ranking { padding: 0; margin: 20px 0 25px; list-style: none; }
#ranking li { display: flex; gap: 10px; align-items: center; padding: 10px 5px; border-bottom: 1px solid #adbd9d20; font-size: 13px; text-align: left; }
#ranking li.is-you { background: linear-gradient(100deg, #e4bf5d26, #e4bf5d0b); border: 1px solid #d1b16066; border-radius: 10px; padding-inline: 10px; font-weight: 750; }
#ranking li > span:first-child { font: italic 19px/1 Georgia, serif; color: #d4b975; width: 14px; }
#ranking img { width: 34px; height: 34px; object-fit: contain; }
#ranking strong { margin-left: auto; font-size: 11px; color: #edcc83; }
.result-player { flex: 1; min-width: 0; }
.result-player > span { display: block; }
.result-player small { display: block; margin-top: 4px; color: #aebda7; font-size: 10px; line-height: 1.5; font-weight: 400; overflow-wrap: anywhere; }
@media (hover: hover) {
    .hand .card.playable:hover { transform: translateY(-3px); border-color: #ffe3a0; }
    .hand .card.selected:hover { transform: translateY(-7px); border-color: #fff1b6; }
    button.primary:not(:disabled):hover { filter: brightness(1.08); }
    .icon-button:hover { background: #d2b16d1a; }
}
@media (max-width: 359px) {
    .player-area { padding-inline: 8px; }
    .hand { gap: 10px 4px; min-height: 151px; }
    .hand .card { height: 67px; font-size: 18px; }
    .hand .card .suit { top: 24px; font-size: 11px; }
    .hand .card::before { font-size: 23px; bottom: 14px; right: 4px; }
    .portrait { width: 64px; height: 64px; }
    .arena { padding-inline: 10px; }
}
@media (max-height: 740px) {
    .arena { padding-top: 14px; }
    .opponents { min-height: 100px; }
    .opponent { padding-top: 8px; }
    .portrait { width: 58px; height: 58px; }
    .opponent-name { margin-top: 6px; }
    .bubble { height: 28px; margin-top: 2px; font-size: 10px; line-height: 14px; }
    .table-center { min-height: 138px; padding: 8px 0 4px; }
    #status { margin-bottom: 8px; }
    .pile { min-height: 76px; }
    .pile .card { height: 76px; }
    .event { min-height: 16px; margin-top: 7px; }
    .player-area { padding-top: 4px; }
    .player-label { margin-bottom: 6px; }
    .hand { min-height: 143px; gap: 9px 4px; }
    .hand .card { height: 64px; }
    .controls { margin-top: 8px; }
}
@media (prefers-reduced-motion: no-preference) {
    button, .portrait { transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease, background-color .14s ease; }
    #result.is-victory[open] .result-crown { animation: crown-arrive .55s ease-out both; }
    .revolution:not([hidden]) { animation: revolution-arrive .3s ease-out both; }
}
@keyframes crown-arrive { from { opacity: 0; transform: translateY(6px) scale(.8); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes revolution-arrive { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

/* Keep table choice beside the start action, outside the hand controls. */
.start-options { position: absolute; top: 62px; display: grid; gap: 8px; width: min(220px, 100%); }
.start-options #table-choice { width: 100%; max-width: none; }
.start-options .start-button { position: static; width: 100%; }
.remaining.is-near { min-width: 54px; right: -6px; border: 2px solid #ffe5a2; color: #3c2a14; background: #ffe5a2; font-weight: 850; box-shadow: 0 0 0 2px #142e2b; }
#status { max-width: 100%; text-align: center; }
/* Six full-width targets; compact faces keep thirteen cards within three rows. */
@media (max-width: 389px) {
    .player-area { padding-inline: 8px; }
    .hand { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px 4px; min-height: 156px; }
    .hand .card { height: 44px; font-size: 18px; }
    .hand .card-rank { top: 5px; left: 4px; }
    .hand .card .suit { top: 5px; left: auto; right: 4px; font-size: 13px; }
    .hand .card::before { right: 5px; bottom: 4px; font-size: 19px; }
    .hand .card::after { display: none; }
}
@media (max-height: 740px) {
    .table.is-idle .table-center { min-height: 185px; }
}
