:root {
  color-scheme: light;
  --ink: #1d2733;
  --muted: #667389;
  --paper: #f7f4ef;
  --panel: #fffdf8;
  --line: #d8cdbc;
  --accent: #2e7d74;
  --accent-2: #b8455a;
  --gold: #c49a3a;
  --shadow: 0 18px 50px rgba(39, 33, 25, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(46,125,116,.14), transparent 36%),
    linear-gradient(250deg, rgba(184,69,90,.13), transparent 34%),
    var(--paper);
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,.04);
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }

.app {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 10px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1;
}

h2 {
  font-size: 15px;
  margin: 0 0 10px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.icon-button {
  width: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.board {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 260px;
  gap: 10px;
  align-items: stretch;
}

.players,
.sidepanel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding: 8px;
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,253,248,.82);
  box-shadow: 0 6px 24px rgba(39, 33, 25, .08);
}

.player.active { outline: 3px solid rgba(46,125,116,.28); }
.player.human { background: #fffaf1; }

.portrait {
  position: relative;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  background-image: var(--portrait);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(0,0,0,.08);
}

.portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 -34px 34px rgba(255,253,248,.16);
  pointer-events: none;
}

.face,
.accentmark { display: none; }

.p0 { --portrait: url("assets/character-kazuya.png"); }
.p1 { --portrait: url("assets/character-kazuno.png"); }
.p2 { --portrait: url("assets/character-nanayo.png"); }
.p3 { --portrait: url("assets/character-mayoi.png"); }

.pname {
  margin: 0 0 3px;
  font-weight: 800;
  font-size: 14px;
}

.ptag {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.quote {
  margin: 0 0 6px;
  padding: 5px 7px;
  border-left: 3px solid var(--accent);
  background: rgba(46,125,116,.08);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.25;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scoreline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
  font-weight: 700;
}

.table-area {
  display: grid;
  grid-template-rows: auto minmax(154px, 1fr) auto auto;
  gap: 8px;
  min-height: calc(100vh - 92px);
}

.statusline,
.panel,
.controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,253,248,.9);
  box-shadow: var(--shadow);
}

.statusline {
  min-height: 42px;
  padding: 10px 12px;
  font-weight: 800;
  font-size: 14px;
}

.trick {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 8px;
  align-content: center;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(46,125,116,.09) 1px, transparent 1px),
    linear-gradient(rgba(46,125,116,.08) 1px, transparent 1px),
    rgba(255,253,248,.55);
  background-size: 28px 28px;
}

.slot {
  min-height: 154px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(102,115,137,.45);
  border-radius: 8px;
  padding: 10px;
}

.slotname {
  align-self: end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.controls {
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.controls label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-weight: 700;
  font-size: 13px;
}

input[type="number"] {
  width: 72px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.hand {
  min-height: 142px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 7px 3px 2px;
}

.cardbutton {
  display: block;
  flex: 1 1 58px;
  min-width: 58px;
  max-width: 78px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
}

.cardbutton:disabled { opacity: 1; }

.card {
  position: relative;
  width: 100%;
  height: 122px;
  border: 1px solid #b9ad9b;
  border-radius: 8px;
  padding: 7px;
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 7px 18px rgba(39,33,25,.14);
  text-align: left;
  transition: transform .14s ease, filter .14s ease;
}

.card.playable:hover,
.card.selectable:hover { transform: translateY(-7px); }
.card.unplayable { filter: grayscale(1); opacity: .42; }
.card.selected { outline: 3px solid var(--accent-2); transform: translateY(-9px); }
.card.major { background: linear-gradient(145deg, #25263a, #5d3154); color: white; border-color: #6e5d79; }
.card.fool { background: linear-gradient(145deg, #fff9d7, #dfeff0); border-color: var(--gold); }
.card.danger::before {
  content: "!";
  position: absolute;
  right: 7px;
  top: 6px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  font-weight: 900;
  font-size: 12px;
}

.card .big {
  display: block;
  font-size: 22px;
  line-height: 1;
  font-weight: 900;
}

.card .suit {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 800;
}

.card .name {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  line-height: 1.22;
  color: inherit;
}

.card .point {
  position: absolute;
  left: 7px;
  bottom: 6px;
  color: var(--accent-2);
  font-weight: 900;
  font-size: 11px;
}

.panel {
  padding: 9px;
}

.statgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.stat {
  border: 1px solid rgba(216,205,188,.75);
  border-radius: 8px;
  padding: 7px;
  background: #fff;
}

.stat b {
  display: block;
  font-size: 15px;
}

.stat span,
.danger-list,
.log {
  color: var(--muted);
  font-size: 12px;
}

.danger-list {
  display: grid;
  gap: 4px;
}

.danger-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(216,205,188,.65);
  padding-bottom: 5px;
}

.logpanel { min-height: 120px; }
.log {
  max-height: 150px;
  overflow: auto;
  line-height: 1.45;
}

.toast {
  color: var(--accent-2);
  font-weight: 800;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(29, 39, 51, .34);
}

.help-overlay[hidden] {
  display: none;
}

.help-card {
  width: min(860px, 100%);
  max-height: min(82vh, 720px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(20, 16, 12, .28);
  padding: 16px;
}

.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.help-head h2 {
  margin: 0;
  font-size: 20px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.help-grid div {
  border: 1px solid rgba(216,205,188,.8);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.help-grid h3 {
  margin: 0 0 7px;
  font-size: 15px;
}

.help-grid p {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.help-grid p:last-child {
  margin-bottom: 0;
}

@media (max-width: 1120px) {
  .board { grid-template-columns: 1fr; }
  .players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidepanel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table-area { min-height: auto; }
}

@media (max-width: 680px) {
  .app { padding: 10px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .players,
  .sidepanel { grid-template-columns: 1fr; }
  .trick { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px; }
  .slot { min-height: 170px; }
  .cardbutton { min-width: 64px; max-width: 82px; }
  .card { width: 100%; height: 136px; }
  .help-grid { grid-template-columns: 1fr; }
}
