:root {
  --ink: #17130f;
  --soft-ink: #40352c;
  --muted: #897b6d;
  --surface: rgba(255, 249, 237, 0.88);
  --surface-solid: #fff8eb;
  --line: rgba(23, 19, 15, 0.14);
  --accent: #b94731;
  --accent-dark: #6f281b;
  --good: #247755;
  --bad: #a23a35;
  --shadow: 0 22px 70px rgba(58, 39, 24, 0.14);
  --mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 18%, rgba(185, 71, 49, 0.18), transparent 23rem),
    radial-gradient(circle at 88% 6%, rgba(23, 19, 15, 0.11), transparent 24rem),
    linear-gradient(135deg, #e4d4bd 0%, #f7eddd 48%, #d7c0a1 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: linear-gradient(rgba(23,19,15,0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(23,19,15,0.035) 1px, transparent 1px);
  background-size: 34px 34px;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.42; }
a { color: inherit; text-decoration: none; }
.skip-link { position: fixed; top: 10px; left: 10px; transform: translateY(-140%); padding: 10px 14px; border-radius: 999px; background: var(--ink); color: #fff7e8; z-index: 5; }
.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(1500px, calc(100vw - 24px));
  height: 100dvh;
  margin: 0 auto;
  padding: 12px 0;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
  gap: 10px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-button {
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 900;
  letter-spacing: -0.04em;
}
.brand-mark { width: 17px; height: 17px; background: var(--accent); clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); }
.app-tabs { display: inline-flex; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 249, 237, 0.62); backdrop-filter: blur(18px); }
.app-tabs button { min-width: 66px; border: 0; border-radius: 999px; padding: 8px 12px; color: var(--muted); background: transparent; font-weight: 800; }
.app-tabs button.active { color: #fff7e8; background: var(--ink); }

.view { display: none; min-height: 0; height: 100%; overflow: hidden; animation: enter 220ms ease both; }
.view.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.eyebrow, .card-label, .status-text, .preview-topline span, .room-chip span, .hand-title span, .log-item small, .prize-block span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.hero-layout { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: stretch; }
.hero-copy, .phone-preview, .create-card, .app-card, .score-panel, .table-panel, .log-panel, .rules-grid article {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.hero-copy { border-radius: 34px; padding: clamp(22px, 4vw, 46px); display: grid; align-content: center; }
.hero-copy h1, .section-heading h2, .lobby-head h2, .table-topline h2 {
  margin: 8px 0 0;
  font-size: clamp(48px, 8vw, 118px);
  line-height: 0.84;
  letter-spacing: -0.09em;
  text-wrap: balance;
}
.lead { max-width: 620px; margin: 20px 0 0; color: var(--soft-ink); font-size: 16px; line-height: 1.65; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 26px; }
.primary-button, .secondary-button, .ghost-button, .bot-actions button, .card-button { border: 0; transition: transform 160ms ease, background 160ms ease, opacity 160ms ease; }
.primary-button, .secondary-button, .ghost-button { min-height: 42px; padding: 10px 16px; border-radius: 999px; font-weight: 850; white-space: nowrap; }
.primary-button { color: #fff7e8; background: var(--ink); }
.secondary-button { color: #fff7e8; background: var(--accent-dark); }
.ghost-button { color: var(--ink); background: rgba(255, 249, 237, 0.62); border: 1px solid var(--line); }
.primary-button:hover:not(:disabled), .secondary-button:hover:not(:disabled), .ghost-button:hover:not(:disabled), .bot-actions button:hover:not(:disabled), .card-button:hover:not(:disabled) { transform: translateY(-2px); }

.phone-preview { border-radius: 34px; padding: 20px; display: grid; align-content: center; gap: 10px; }
.preview-topline, .preview-row, .score-row, .card-topline, .lobby-head, .table-topline, .copy-row, .join-form { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.preview-prize { width: 96px; height: 126px; display: grid; place-items: center; margin: 12px auto 18px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface-solid); color: var(--good); font-family: var(--mono); font-size: 38px; font-weight: 900; }
.preview-row { min-height: 56px; border-top: 1px solid var(--line); }
.preview-row strong { font-family: var(--mono); font-size: 28px; }
.preview-row.muted { opacity: 0.46; text-decoration: line-through; }
.preview-row.win { color: var(--good); }

.view-create.active { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(360px, 0.75fr); gap: 16px; align-items: stretch; }
.section-heading { border-radius: 34px; padding: 30px; background: rgba(255,249,237,0.44); display: grid; align-content: center; }
.section-heading h2 { font-size: clamp(46px, 7vw, 96px); }
.create-card { min-height: 0; padding: 24px; border-radius: 34px; display: grid; align-content: center; gap: 12px; }
.create-card label { font-size: 30px; font-weight: 900; letter-spacing: -0.06em; }
input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 999px; padding: 0 16px; color: var(--ink); background: rgba(255, 249, 237, 0.78); outline: none; }
input:focus { border-color: rgba(185, 71, 49, 0.58); }

.view-lobby.active { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 10px; }
.lobby-head { min-height: 86px; padding: 0 4px; align-items: center; }
.lobby-head h2 { font-size: clamp(42px, 6vw, 74px); }
.room-chip { min-width: 206px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); text-align: right; }
.room-chip strong { display: block; margin-top: 4px; font-family: var(--mono); font-size: 30px; letter-spacing: 0.08em; }
.lobby-grid { min-height: 0; display: grid; grid-template-columns: minmax(0, 0.92fr) minmax(340px, 1.08fr); grid-template-areas: "invite seats" "join seats" "bot seats"; gap: 12px; }
.invite-card { grid-area: invite; }
.join-card { grid-area: join; }
.bot-card { grid-area: bot; }
.seats-card { grid-area: seats; }
.app-card { min-height: 0; padding: 18px; border-radius: 28px; overflow: hidden; }
.card-topline h3 { margin: 6px 0 0; font-size: 34px; letter-spacing: -0.08em; }
.player-list { max-height: calc(100dvh - 260px); overflow: auto; display: grid; gap: 8px; margin-top: 18px; padding-right: 4px; }
.player-row { min-height: 58px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.seat-dot { width: 11px; height: 11px; border-radius: 999px; background: var(--good); }
.seat-dot.bot { background: var(--accent); }
.player-row div { flex: 1; display: grid; gap: 2px; }
.player-row strong { font-size: 18px; letter-spacing: -0.04em; }
.player-row em { color: var(--accent-dark); font-style: normal; font-weight: 900; }
.bot-actions { display: grid; gap: 8px; margin-top: 12px; }
.bot-actions button { min-height: 52px; padding: 0 14px; border-radius: 18px; color: var(--ink); background: rgba(255, 249, 237, 0.76); border: 1px solid var(--line); text-align: left; display: flex; justify-content: space-between; align-items: center; }
.bot-actions span { color: var(--muted); }

.view-game.active { display: block; }
.game-grid { height: 100%; display: grid; grid-template-columns: 230px minmax(0, 1fr) 280px; gap: 12px; }
.score-panel, .table-panel, .log-panel { min-height: 0; height: 100%; border-radius: 28px; padding: 16px; overflow: hidden; }
.score-list, .log-list { height: calc(100% - 56px); overflow: auto; display: grid; align-content: start; gap: 8px; margin-top: 12px; padding-right: 4px; }
.score-row { min-height: 48px; border-bottom: 1px solid var(--line); }
.score-row.self { color: var(--accent-dark); }
.score-row strong { font-family: var(--mono); font-size: 24px; }
.table-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; }
.table-topline { align-items: start; }
.table-topline h2 { font-size: clamp(30px, 4vw, 58px); }
.prize-block { display: grid; justify-items: end; gap: 6px; }
.prize-card { width: 82px; height: 108px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 20px; background: var(--surface-solid); box-shadow: 0 14px 32px rgba(58, 39, 24, 0.13); font-family: var(--mono); font-size: 32px; }
.positive { color: var(--good); }
.negative { color: var(--bad); }
.table-center { min-height: 0; overflow: hidden; display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; align-content: center; }
.played-seat { min-height: 128px; padding: 12px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,0.28); display: grid; place-items: center; gap: 8px; }
.played-seat.self { outline: 2px solid rgba(185, 71, 49, 0.28); }
.played-card { width: 62px; height: 82px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-solid); font-family: var(--mono); font-size: 18px; font-weight: 900; }
.played-card.back { color: #fff7e8; background: repeating-linear-gradient(45deg, var(--accent-dark), var(--accent-dark) 8px, #8e3423 8px, #8e3423 16px); }
.result-banner { grid-column: 1 / -1; padding: 12px; border-radius: 18px; background: var(--ink); color: #fff7e8; text-align: center; }
.hand-dock { border-top: 1px solid var(--line); padding-top: 12px; }
.hand-title { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.hand-title strong { font-size: 22px; letter-spacing: -0.06em; }
.hand-grid { display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.card-button { min-height: 52px; border-radius: 13px; color: var(--ink); background: var(--surface-solid); border: 1px solid var(--line); font-family: var(--mono); font-size: 17px; font-weight: 900; }
.card-button:disabled { color: rgba(23,19,15,0.25); background: rgba(255,255,255,0.22); text-decoration: line-through; }
.log-item, .empty-state { padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--soft-ink); line-height: 1.45; font-size: 14px; }
.log-item p { margin: 5px 0; }
.empty-state.wide { grid-column: 1 / -1; text-align: center; border: 0; }

.view-rules.active { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 16px; }
.rules-grid { min-height: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.rules-grid article { min-height: 0; padding: 18px; border-radius: 26px; display: grid; align-content: space-between; }
.rules-grid span { font-family: var(--mono); color: var(--muted); }
.rules-grid strong { display: block; font-size: 30px; letter-spacing: -0.08em; }
.rules-grid p { color: var(--soft-ink); line-height: 1.55; margin: 12px 0 0; }

@media (max-width: 1100px) {
  .app-shell { width: min(100vw - 18px, 1500px); }
  .hero-layout, .view-create.active, .lobby-grid, .game-grid, .view-rules.active { grid-template-columns: 1fr; }
  .phone-preview { display: none; }
  .lobby-grid { grid-template-areas: "invite" "join" "bot" "seats"; }
  .score-panel, .log-panel { display: none; }
  .table-panel { height: 100%; }
  .rules-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-shell { width: min(100vw - 12px, 1500px); padding: 8px 0; grid-template-rows: auto minmax(0, 1fr); }
  .app-header { align-items: stretch; flex-direction: column; gap: 8px; }
  .app-tabs { width: 100%; overflow-x: auto; justify-content: space-between; }
  .app-tabs button { min-width: 62px; padding: 8px 10px; }
  .hero-copy h1, .section-heading h2, .lobby-head h2 { font-size: clamp(40px, 14vw, 64px); }
  .hero-copy, .section-heading, .create-card, .app-card, .score-panel, .table-panel, .log-panel { border-radius: 22px; padding: 14px; }
  .lead { font-size: 14px; line-height: 1.55; }
  .lobby-head { min-height: auto; align-items: start; flex-direction: column; }
  .room-chip { text-align: left; width: 100%; min-width: 0; }
  .copy-row, .join-form, .card-topline, .table-topline { align-items: stretch; flex-direction: column; }
  .rules-grid { grid-template-columns: 1fr; overflow: auto; }
  .hand-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .card-button { min-height: 44px; }
  .table-center { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
