:root {
  --ink: #17202a;
  --ink2: #0d141a;
  --gold: #c99537;
  --gold2: #f0d879;
  --felt: #2c6e49;
  --felt2: #1e5638;
  --paper: #f4f6f7;
  --red: #a62929;
  --green: #258b45;
  --muted: #aeb6bf;
  --shadow: 0 16px 40px #0008;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at 50% -10%, #314557 0, var(--ink) 40%, #0b1116 100%);
  color: #f6f1e6;
  font: 16px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }
.start-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.start-card {
  width: min(720px, 100%);
  padding: 30px;
  text-align: center;
  background: linear-gradient(145deg, #1d2a36, #101820);
  border: 1px solid #ffffff18;
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.start-logo { width: clamp(130px, 24vw, 190px); filter: drop-shadow(0 8px 18px #0009); }
h1 { margin: 4px 0 0; font-size: clamp(34px, 7vw, 52px); }
.gold { color: var(--gold2); font-size: clamp(18px, 3.2vw, 23px); font-weight: 650; margin: 6px 0 16px; }
.version { color: var(--muted); margin: 18px 0 0; }
.start-actions, .language-switch, .game-actions, .header-actions, .modal-actions {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.icon-button {
  position: relative;
  border: 3px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  padding: 3px;
  cursor: pointer;
  transition: .16s;
}
.icon-button:hover, .icon-button:focus-visible { border-color: var(--gold2); outline: none; transform: translateY(-1px); }
.icon-button:disabled { opacity: .35; cursor: not-allowed; transform: none; border-color: transparent; }
.icon-button img { display: block; width: 68px; height: 68px; object-fit: contain; }
.icon-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.start-button img { width: 106px; height: 106px; }
.start-actions { margin-top: 12px; }
.language-switch { margin-top: 14px; }
.language-switch button { background: #101820; border: 2px solid #626a73; border-radius: 8px; padding: 4px; cursor: pointer; }
.language-switch button.active, .language-switch button:hover { border-color: var(--gold2); }
.language-switch img { display: block; width: 54px; height: 34px; object-fit: cover; }
.primary-button, .secondary-button {
  border: 2px solid var(--gold); border-radius: 10px; padding: 10px 18px; font-weight: 700; cursor: pointer;
}
.primary-button { background: var(--green); color: #fff; }
.secondary-button { background: #263541; color: #fff; }
.primary-button:hover, .secondary-button:hover { border-color: var(--gold2); filter: brightness(1.08); }
.primary-button:disabled, .secondary-button:disabled { opacity: .4; cursor: not-allowed; filter: none; }

.game-screen { min-height: 100vh; padding: 10px; display: grid; grid-template-rows: auto minmax(420px, 1fr) auto; gap: 10px; }
.game-header { display: flex; align-items: center; justify-content: space-between; background: #101820; border-radius: 15px; padding: 7px 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: clamp(19px, 3vw, 27px); }
.brand img { width: 56px; height: 56px; object-fit: contain; }
.web-badge { font-size: 11px; padding: 3px 6px; border: 1px solid var(--gold); border-radius: 999px; color: var(--gold2); }
.icon-button.small img { width: 50px; height: 50px; }
.icon-button.danger:hover { border-color: #f06d6d; }
.table-shell {
  position: relative;
  min-height: 440px;
  overflow: hidden;
  border: 3px solid #1a1108;
  border-radius: clamp(60px, 17vw, 190px);
  background: radial-gradient(ellipse at center, var(--felt) 0, var(--felt) 58%, var(--felt2) 100%);
  box-shadow: inset 0 0 0 7px #8e6421, inset 0 0 0 10px #f4d779, inset 0 0 0 14px #60400f, var(--shadow);
}
body[data-design="modern"] .table-shell { background: radial-gradient(ellipse at center, #276d67 0, #1d5a50 58%, #143b3b 100%); }
.table-decor { position: absolute; pointer-events: none; opacity: .88; }
.table-decor img { width: 120px; max-height: 110px; object-fit: contain; }
.discard { top: 36px; left: 48px; }
.sweets { top: 33px; right: 48px; }
.score { bottom: 33px; left: 48px; }
.chips { bottom: 32px; right: 48px; }
.seat { position: absolute; display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 110px; }
.seat-top { top: 22px; left: 50%; transform: translateX(-50%); }
.seat-left { left: 35px; top: 50%; transform: translateY(-50%); }
.seat-right { right: 35px; top: 50%; transform: translateY(-50%); }
.seat-human { bottom: 18px; left: 50%; transform: translateX(-50%); }
.seat-card { padding: 6px 9px; border: 3px solid #ffffffcc; border-radius: 13px; background: #173525cc; box-shadow: 0 7px 18px #0007; min-width: 105px; }
.seat-card.current { border-color: var(--gold2); box-shadow: 0 0 0 3px #8b621b, 0 7px 18px #0009; }
.seat-card.warning { border-color: #ff4e4e; }
.seat-card.warning .seat-name, .seat-card.warning .card-count { color: #ffe058; }
.avatar { width: 64px; height: 64px; border-radius: 9px; object-fit: cover; background: #ddd; }
.seat-name { font-weight: 750; }
.card-count { font-size: 13px; color: #ecf2ed; }
.dots { letter-spacing: 1px; color: #eee; font-size: 11px; }
.one-card { color: #ffe058; font-weight: 800; }
.table-center { position: absolute; inset: 25% 24%; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; overflow: auto; }
.move { width: min(430px, 100%); background: #10241dcc; border: 1px solid #ffffff25; border-radius: 12px; padding: 8px; text-align: center; }
.move.current { border-color: var(--gold2); background: #132c22; }
.mini-cards, .tip-cards { display: flex; justify-content: center; gap: 3px; margin-top: 5px; flex-wrap: wrap; }
.mini-card { min-width: 34px; padding: 4px 5px; background: #fff; border: 1px solid #202020; border-radius: 5px; color: #111; font-weight: 800; box-shadow: 0 2px 5px #0005; }
.table-center .mini-card { min-width: 42px; padding: 6px 8px; font-size: 16px; }
.mini-card.red { color: #b21321; }

.control-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(200px, 260px); gap: 10px; align-items: stretch; }
.hand-area, .leaderboard { border-radius: 13px; background: #101820; padding: 10px; min-width: 0; }
.hand-heading { display: flex; justify-content: space-between; gap: 10px; min-height: 27px; color: var(--gold2); }
.hand { display: flex; align-items: flex-end; overflow-x: auto; padding: 12px 4px 5px; min-height: 148px; }
.playing-card { flex: 0 0 78px; width: 78px; height: 118px; margin-right: -26px; border: 2px solid #242424; border-radius: 9px; background: linear-gradient(145deg, #fff, #eee); color: #111; box-shadow: 0 5px 12px #0007; padding: 6px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; font-weight: 850; cursor: pointer; transition: .15s; }
.playing-card:last-child { margin-right: 0; }
.playing-card > span:nth-child(2) { align-self: center; font-size: 30px; }
.playing-card .bottom { align-self: flex-end; transform: rotate(180deg); }
.playing-card.red { color: #bd1425; }
.playing-card:hover, .playing-card:focus-visible { transform: translateY(-9px); z-index: 2; outline: 3px solid #fff9; }
.playing-card.selected { transform: translateY(-19px); outline: 4px solid var(--gold2); z-index: 3; }
.game-actions { align-content: center; background: #101820; border-radius: 13px; padding: 7px; max-width: 190px; }
.icon-button.action img { width: 58px; height: 58px; }
.leaderboard { color: #17202a; background: #e7dbc0; border: 3px double #805813; }
.leaderboard h2 { margin: 0 0 5px; font-size: 19px; text-align: center; }
.leaderboard ol { padding-left: 27px; margin: 0; }
.leaderboard li { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 6px; margin: 4px 0; font-weight: 700; }
.leaderboard li img { width: 25px; height: 25px; object-fit: cover; border-radius: 4px; }

.modal { width: min(650px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid #ffffff20; border-radius: 18px; color: #17202a; background: #f8f8f6; box-shadow: var(--shadow); overflow: hidden; }
.modal.wide { width: min(980px, calc(100vw - 24px)); }
.modal.compact { width: min(540px, calc(100vw - 24px)); }
.modal::backdrop { background: #03080dc9; backdrop-filter: blur(3px); }
.modal-heading { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; background: #17202a; color: #fff; }
.modal-heading h2 { margin: 0; }
.close-button { width: 42px; height: 42px; border: 2px solid transparent; border-radius: 8px; color: #fff; background: transparent; font-size: 30px; cursor: pointer; }
.close-button:hover, .close-button:focus-visible { border-color: var(--gold2); outline: none; }
.modal-scroll { max-height: calc(100vh - 230px); overflow: auto; padding: 18px; }
.settings-section { border: 2px solid; border-radius: 12px; padding: 15px; margin-bottom: 18px; }
.settings-section h3 { margin: 0 0 8px; font-size: 21px; }
.live-section { border-color: #387652; }
.live-section h3 { color: #207443; }
.restart-section { border-color: #b43636; }
.restart-section h3 { color: #8e2424; }
.section-note { margin: 0 0 14px; padding: 10px; border-radius: 8px; font-weight: 650; }
.live-section .section-note { background: #e7f7ec; color: #207443; }
.restart-section .section-note { background: #ffe7e9; color: #821919; }
.settings-grid { display: grid; gap: 13px; }
.settings-grid > label, .computer-names label { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(190px, 1.2fr); align-items: center; gap: 14px; font-weight: 700; }
.settings-grid input, .settings-grid select { width: 100%; min-width: 0; border: 1px solid #9aa1a7; border-radius: 7px; padding: 8px; background: #fff; color: #17202a; }
.settings-grid input[type="checkbox"] { width: 22px; height: 22px; justify-self: end; accent-color: #258b45; }
.settings-grid .checkbox-row { grid-template-columns: 1fr auto; }
.settings-grid .checkbox-row input { order: 2; }
.settings-grid fieldset { border: 1px solid #c2c6c9; border-radius: 9px; padding: 10px; }
.settings-grid legend { font-weight: 800; padding: 0 6px; }
.design-options, .avatar-options { display: flex; gap: 8px; flex-wrap: wrap; }
.design-choice, .avatar-choice { border: 2px solid #ccd0d3; border-radius: 9px; background: transparent; color: #17202a; cursor: pointer; padding: 6px; }
.design-choice { width: 96px; font-weight: 800; }
.design-choice img { width: 58px; height: 58px; object-fit: contain; display: block; margin: auto; }
.design-choice.active, .avatar-choice.active, .design-choice:hover, .avatar-choice:hover { border: 4px solid var(--gold); padding: 4px; background: #fffbee; }
.avatar-choice img { width: 62px; height: 62px; border-radius: 7px; object-fit: cover; display: block; }
.file-choice { display: inline-grid !important; grid-template-columns: auto !important; gap: 6px !important; margin-top: 10px; font-weight: 700; }
.file-choice input { font-weight: 400; }
.computer-names { display: grid; gap: 7px; }
.computer-names label { grid-template-columns: 100px 1fr; }
.fixed-actions { min-height: 92px; justify-content: flex-end; padding: 9px 20px; background: #17202a; }
.dialog-action img { width: 62px; height: 62px; }
.help-content { max-height: calc(100vh - 185px); overflow: auto; padding: 22px 28px; background: #fff; }
.help-content h2 { color: #7f5311; }
.help-content h3 { color: #1f6843; margin: 26px 0 7px; padding-bottom: 4px; border-bottom: 1px solid #d8d1c0; }
.help-content p { color: #26333d; }
.pre-line { white-space: pre-line; }
.rule-order, .rule-example, .score-example { border: 2px solid var(--gold); border-radius: 10px; background: #fff9df; padding: 10px 13px; font-weight: 700; white-space: pre-line; }
.help-image { width: 100%; max-height: 520px; object-fit: contain; border: 2px solid #876019; border-radius: 12px; background: #17202a; }
.help-icon-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 12px 0; }
.help-icon-grid > div { display: grid; grid-template-columns: 66px 1fr; gap: 8px; align-items: center; border: 1px solid #d3d6d7; border-radius: 9px; padding: 7px; }
.help-icon-grid img { width: 62px; height: 62px; object-fit: contain; }
.help-icon-grid p { margin: 0; }
.help-topic { border-left: 4px solid var(--gold); margin: 9px 0; padding: 5px 10px; }
.help-topic p { margin: 4px 0; }
#tips-intro { white-space: pre-line; padding: 0 20px; }
.tips-list { max-height: calc(100vh - 260px); overflow: auto; display: grid; gap: 9px; padding: 0 20px 20px; }
.tip-row { display: grid; grid-template-columns: minmax(120px, .7fr) minmax(180px, 1.2fr) auto; align-items: center; gap: 12px; border: 2px solid #c3c7ca; border-radius: 10px; padding: 9px; }
.tip-row.playable { border-color: #26964b; background: #eaf8ef; }
.opening-message { display: grid; grid-template-columns: 110px 1fr; gap: 18px; align-items: center; padding: 24px; font-size: 18px; font-weight: 700; }
.opening-avatar { width: 105px; height: 105px; object-fit: cover; border: 4px solid var(--gold); border-radius: 14px; }
.result-text { font-size: 20px; font-weight: 750; padding: 12px 20px; }
.result-ranking { padding: 0 20px 15px; }
.result-ranking > div { display: flex; justify-content: space-between; border-bottom: 1px solid #bbb; padding: 7px 2px; }
.modal > .modal-actions:not(.fixed-actions), .modal > div + .modal-actions { padding: 15px 20px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 25px; transform: translate(-50%, 25px); max-width: min(600px, calc(100vw - 28px)); padding: 12px 18px; border: 2px solid var(--gold2); border-radius: 12px; background: #101820; color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .game-screen { grid-template-rows: auto minmax(470px, 1fr) auto; }
  .control-panel { grid-template-columns: 1fr auto; }
  .leaderboard { grid-column: 1 / -1; }
  .leaderboard ol { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 22px; }
  .table-decor img { width: 88px; max-height: 78px; }
  .discard { top: 30px; left: 30px; }
  .sweets { top: 28px; right: 30px; }
  .score { bottom: 28px; left: 30px; }
  .chips { bottom: 27px; right: 30px; }
  .seat-left { left: 16px; }
  .seat-right { right: 16px; }
  .table-center { inset: 27% 21%; }
}
@media (max-width: 680px) {
  .start-card { padding: 21px 12px; }
  .game-screen { padding: 5px; gap: 5px; grid-template-rows: auto minmax(500px, 1fr) auto; }
  .game-header { align-items: flex-start; padding: 6px; }
  .brand strong { display: none; }
  .brand img { width: 42px; height: 42px; }
  .header-actions { justify-content: flex-end; gap: 1px; }
  .icon-button.small img { width: 42px; height: 42px; }
  .table-shell { min-height: 500px; border-radius: 55px; }
  .table-decor { opacity: .4; }
  .discard { left: 18px; top: 18px; }
  .sweets { right: 18px; top: 18px; }
  .score { left: 18px; bottom: 18px; }
  .chips { right: 18px; bottom: 18px; }
  .seat-top { top: 10px; }
  .seat-left { left: 8px; top: 43%; }
  .seat-right { right: 8px; top: 43%; }
  .seat-human { bottom: 8px; }
  .seat-card { min-width: 82px; padding: 4px; }
  .avatar { width: 48px; height: 48px; }
  .seat-name { max-width: 82px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .card-count, .dots { font-size: 10px; }
  .table-center { inset: 28% 12% 29%; }
  .move { font-size: 12px; padding: 5px; }
  .mini-card { min-width: 28px; padding: 2px 3px; font-size: 12px; }
  .table-center .mini-card { min-width: 33px; padding: 3px 5px; font-size: 13px; }
  .control-panel { display: block; }
  .hand-area { border-radius: 10px 10px 0 0; }
  .game-actions { max-width: none; border-radius: 0 0 10px 10px; display: flex; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; }
  .icon-button.action img { width: 50px; height: 50px; }
  .leaderboard { margin-top: 5px; }
  .leaderboard ol { grid-template-columns: 1fr; }
  .playing-card { flex-basis: 67px; width: 67px; height: 103px; margin-right: -29px; }
  .modal-scroll { padding: 10px; }
  .settings-section { padding: 10px; }
  .settings-grid > label, .computer-names label { grid-template-columns: 1fr; gap: 5px; }
  .settings-grid .checkbox-row { grid-template-columns: 1fr auto; }
  .settings-grid .checkbox-row input { order: 2; }
  .help-content { padding: 16px; }
  .help-icon-grid { grid-template-columns: 1fr; }
  .tip-row { grid-template-columns: 1fr; text-align: center; }
  .opening-message { grid-template-columns: 1fr; text-align: center; }
  .opening-avatar { margin: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
