:root {
  color-scheme: dark;
  --ink: #efe3c4;
  --muted: #b9a989;
  --gold: #c4a35a;
  --gold-bright: #e3c779;
  --line: rgba(196, 163, 90, 0.34);
  --panel: rgba(20, 16, 11, 0.88);
  --panel-soft: rgba(35, 28, 19, 0.84);
  --green: #758b64;
  --red: #a65443;
  --blue: #6e8798;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.42);
  font-family:
    "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC",
    Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background:
    linear-gradient(rgba(18, 12, 8, 0.52), rgba(18, 12, 8, 0.68)),
    url("./assets/walnut-world-table.png") center / cover fixed,
    #20150f;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 20%, rgba(223, 190, 119, 0.1), transparent 42%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.38), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.38));
  z-index: -1;
}

button,
input,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: 0.12;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.24'/%3E%3C/svg%3E");
}

.online-header {
  position: sticky;
  top: 0;
  z-index: 12;
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px clamp(18px, 3vw, 50px);
  border-bottom: 1px solid var(--line);
  background: rgba(17, 14, 10, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  color: var(--gold-bright);
  border: 1px solid var(--gold);
  transform: rotate(45deg);
  font: 700 14px/1 Georgia, serif;
}

.brand-mark::first-line {
  transform: rotate(-45deg);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 25px;
  letter-spacing: 0.15em;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font: 10px/1.2 Georgia, serif;
  letter-spacing: 0.33em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-pill,
.presence {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.connection-pill::before,
.presence::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7f715d;
  box-shadow: 0 0 0 3px rgba(127, 113, 93, 0.12);
}

.connection-pill.online::before,
.presence.online::before {
  background: #86a873;
  box-shadow: 0 0 10px rgba(134, 168, 115, 0.8);
}

.presence.in-room::before {
  background: var(--gold);
}

.presence.in-game::before {
  background: #c46a57;
}

.line-button,
.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.mode-card,
.target-button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: rgba(25, 20, 14, 0.78);
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.line-button {
  display: inline-flex;
  align-items: center;
  padding: 0 18px;
  text-decoration: none;
}

button:hover:not(:disabled),
.line-button:hover {
  border-color: var(--gold-bright);
  background: rgba(71, 54, 29, 0.76);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.primary-button {
  padding: 0 24px;
  border-color: rgba(227, 199, 121, 0.7);
  background:
    linear-gradient(rgba(180, 137, 53, 0.28), rgba(102, 72, 27, 0.25)),
    rgba(34, 26, 16, 0.95);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.secondary-button,
.danger-button {
  padding: 0 18px;
}

.danger-button {
  border-color: rgba(166, 84, 67, 0.58);
}

.wide-button {
  width: 100%;
}

#online-app {
  width: min(1500px, calc(100% - 32px));
  min-height: calc(100vh - 78px);
  margin: 0 auto;
  padding: 28px 0 54px;
}

.loading-panel {
  min-height: 60vh;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
}

.seal-spinner {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-bright);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 32px rgba(196, 163, 90, 0.34);
  }
}

.auth-layout {
  min-height: calc(100vh - 160px);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(380px, 520px);
  align-items: center;
  gap: clamp(30px, 7vw, 100px);
}

.auth-intro {
  padding: clamp(12px, 3vw, 42px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font: 12px/1.4 Georgia, serif;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.auth-intro h1,
.page-title h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 72px);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.auth-intro p {
  max-width: 680px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.9;
}

.mode-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.mode-summary span {
  padding: 8px 13px;
  border: 1px solid var(--line);
  background: rgba(16, 13, 9, 0.5);
  color: #d6c9aa;
  font-size: 13px;
}

.panel,
.auth-panel,
.seat-card,
.battle-panel,
.command-panel,
.log-panel {
  border: 1px solid var(--line);
  background:
    linear-gradient(145deg, rgba(58, 44, 27, 0.12), transparent 45%),
    var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel {
  min-height: 510px;
  padding: 28px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.auth-tab {
  min-height: 46px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  cursor: pointer;
}

.auth-tab.active {
  border-bottom-color: var(--gold-bright);
  color: var(--gold-bright);
}

.form-stack {
  display: grid;
  gap: 17px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.inline-select,
.skill-option {
  width: 100%;
  min-height: 45px;
  padding: 0 12px;
  border: 1px solid rgba(196, 163, 90, 0.28);
  border-radius: 0;
  outline: none;
  background: rgba(7, 7, 6, 0.72);
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.inline-select:focus,
.skill-option:focus {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 2px rgba(196, 163, 90, 0.12);
}

.form-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.dev-code {
  padding: 10px 12px;
  border-left: 2px solid var(--gold);
  background: rgba(196, 163, 90, 0.1);
  color: var(--gold-bright);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 4px 0 24px;
}

.page-title h1 {
  font-size: clamp(30px, 4vw, 50px);
}

.page-title p {
  margin: 8px 0 0;
  color: var(--muted);
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(330px, 0.75fr);
  gap: 20px;
}

.panel {
  padding: 22px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 13px;
  margin-top: 18px;
}

.mode-card {
  min-height: 158px;
  padding: 20px;
  text-align: left;
}

.mode-card strong,
.mode-card span {
  display: block;
}

.mode-card strong {
  margin-bottom: 10px;
  font-size: 21px;
}

.mode-card span {
  color: var(--muted);
  line-height: 1.65;
}

.search-row,
.button-row,
.team-row,
.invite-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.search-row {
  margin: 16px 0;
}

.search-row input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(8, 7, 5, 0.75);
  color: var(--ink);
}

.list-stack {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.list-row {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(196, 163, 90, 0.19);
  background: rgba(12, 10, 7, 0.46);
}

.list-row p,
.list-row small {
  margin: 0;
}

.list-row small {
  color: var(--muted);
}

.empty-note {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(196, 163, 90, 0.25);
}

.room-shell {
  display: grid;
  gap: 18px;
}

.room-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.room-code {
  color: var(--muted);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
}

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

.seat-card {
  min-height: 235px;
  padding: 15px;
}

.seat-card.viewer {
  border-color: var(--gold-bright);
  box-shadow:
    var(--shadow),
    inset 0 0 24px rgba(196, 163, 90, 0.08);
}

.seat-card.empty {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: var(--muted);
}

.seat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
}

.seat-top strong {
  font-size: 18px;
}

.seat-status {
  color: var(--muted);
  font-size: 12px;
}

.seat-content {
  display: grid;
  grid-template-columns: 98px minmax(0, 1fr);
  gap: 14px;
}

.seat-content img,
.battle-card-image {
  width: 100%;
  aspect-ratio: 1013 / 1552;
  object-fit: contain;
  border: 1px solid rgba(226, 207, 164, 0.35);
  background: #d7c9a6;
}

.seat-controls {
  display: grid;
  align-content: start;
  gap: 10px;
}

.team-button {
  min-height: 36px;
  flex: 1;
  border: 1px solid var(--line);
  background: rgba(15, 12, 9, 0.7);
}

.team-button.active {
  border-color: var(--gold-bright);
  background: rgba(196, 163, 90, 0.18);
}

.ready-seal {
  color: #92b17c;
}

.battle-shell {
  display: grid;
  gap: 16px;
}

.battle-meta {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

.battle-meta > :last-child {
  text-align: right;
}

.turn-seal {
  min-width: 116px;
  min-height: 116px;
  display: grid;
  place-content: center;
  justify-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: rgba(16, 13, 9, 0.88);
  box-shadow:
    inset 0 0 0 5px rgba(196, 163, 90, 0.1),
    0 0 30px rgba(196, 163, 90, 0.12);
}

.turn-seal strong {
  font-size: 29px;
  color: var(--gold-bright);
}

.turn-seal small {
  color: var(--muted);
}

.pause-banner,
.notice-banner {
  padding: 14px 18px;
  border: 1px solid rgba(166, 84, 67, 0.58);
  background: rgba(72, 27, 22, 0.76);
  text-align: center;
}

.notice-banner {
  border-color: var(--line);
  background: rgba(64, 48, 25, 0.66);
}

.battle-layout {
  display: grid;
  grid-template-columns: minmax(290px, 1fr) minmax(250px, 0.64fr) minmax(290px, 1fr);
  gap: 14px;
  align-items: stretch;
}

.battle-panel,
.command-panel {
  min-height: 530px;
  padding: 16px;
}

.battle-panel.inactive {
  opacity: 0.72;
}

.battle-player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.battle-card {
  display: grid;
  grid-template-columns: 126px minmax(0, 1fr);
  gap: 13px;
}

.battle-card h3 {
  margin: 0 0 5px;
  font-size: 21px;
}

.battle-card p {
  margin: 0;
  color: var(--muted);
}

.skill-stack {
  display: grid;
  gap: 8px;
  margin-top: 15px;
}

.skill-row {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid rgba(196, 163, 90, 0.2);
  background: rgba(10, 9, 7, 0.45);
}

.skill-row.selected {
  border-color: var(--gold-bright);
  background: rgba(196, 163, 90, 0.12);
}

.skill-row.triggered {
  animation: triggered 900ms ease-out;
}

@keyframes triggered {
  35% {
    box-shadow: 0 0 28px rgba(227, 199, 121, 0.55);
  }
}

.skill-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-bright);
  font-weight: 700;
}

.skill-icon.triangle {
  border: 0;
  border-radius: 0;
  background: linear-gradient(60deg, transparent 46%, var(--gold) 47%, var(--gold) 52%, transparent 53%),
    linear-gradient(-60deg, transparent 46%, var(--gold) 47%, var(--gold) 52%, transparent 53%),
    linear-gradient(0deg, var(--gold), var(--gold)) bottom / 78% 1px no-repeat;
}

.skill-icon.square {
  border-radius: 2px;
}

.skill-copy strong,
.skill-copy small {
  display: block;
}

.skill-copy small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
}

.skill-use {
  color: var(--gold-bright);
  font-size: 13px;
}

.skill-action {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 7px;
}

.skill-action button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: rgba(44, 33, 19, 0.9);
}

.command-panel {
  display: grid;
  align-content: start;
  gap: 15px;
  text-align: center;
}

.dice-board {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 9px;
  margin: 8px auto;
}

.die-wrap small {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

.die {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border: 3px double #8a7653;
  border-radius: 12px;
  background: #ded1b1;
  color: #33251c;
  font: 700 34px/1 Georgia, serif;
  box-shadow: inset 0 0 12px rgba(62, 40, 25, 0.28);
}

.damage-line {
  padding: 12px;
  border-block: 1px solid var(--line);
  color: var(--muted);
}

.damage-line strong {
  color: var(--gold-bright);
  font-size: 21px;
}

.target-grid {
  display: grid;
  gap: 9px;
}

.target-button {
  min-height: 54px;
  padding: 10px;
}

.target-button strong,
.target-button small {
  display: block;
}

.target-button small {
  color: var(--muted);
}

.global-seat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.global-seat {
  min-height: 58px;
  padding: 9px;
  border: 1px solid rgba(196, 163, 90, 0.2);
  background: rgba(13, 11, 8, 0.72);
}

.global-seat.active {
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(196, 163, 90, 0.22);
}

.global-seat.dead {
  opacity: 0.42;
  filter: grayscale(1);
}

.global-seat strong,
.global-seat small {
  display: block;
}

.global-seat small {
  color: var(--muted);
}

.log-panel {
  padding: 16px;
}

.log-panel h3 {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 0.14em;
}

.battle-log {
  max-height: 180px;
  overflow: auto;
  display: grid;
  gap: 5px;
  padding-right: 7px;
}

.battle-log p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.gameover-panel {
  min-height: 420px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.gameover-panel h2 {
  margin: 10px 0;
  font-size: clamp(34px, 6vw, 72px);
}

#online-toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 24px;
  max-width: min(560px, calc(100% - 30px));
  transform: translate(-50%, 30px);
  padding: 12px 18px;
  border: 1px solid var(--line);
  background: rgba(13, 11, 8, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

#online-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#online-toast.error {
  border-color: var(--red);
}

@media (max-width: 1050px) {
  .auth-layout,
  .home-grid,
  .lobby-grid {
    grid-template-columns: 1fr;
  }

  .battle-layout {
    grid-template-columns: 1fr 1fr;
  }

  .command-panel {
    grid-column: 1 / -1;
    min-height: 0;
    order: -1;
  }
}

@media (max-width: 720px) {
  .online-header {
    padding: 10px 14px;
  }

  .brand strong {
    font-size: 18px;
  }

  .brand small,
  .connection-pill {
    display: none;
  }

  #online-app {
    width: min(100% - 20px, 1500px);
    padding-top: 18px;
  }

  .auth-layout,
  .seat-grid,
  .mode-grid,
  .battle-layout {
    grid-template-columns: 1fr;
  }

  .auth-panel {
    min-height: 0;
    padding: 18px;
  }

  .page-head,
  .room-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .battle-meta {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .battle-meta > :last-child {
    text-align: center;
  }

  .battle-panel,
  .command-panel {
    min-height: 0;
  }

  .global-seat-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .skill-action {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

