:root {
  color-scheme: dark;
  --bg: #080705;
  --felt: #082a1d;
  --felt-line: rgba(58, 164, 105, 0.12);
  --velvet: #3a0710;
  --velvet-2: #64111d;
  --panel: #120d0a;
  --panel-ink: #fff1ce;
  --panel-muted: #c59c65;
  --dark-panel: #17100d;
  --dark-rail: #28150f;
  --line: rgba(243, 195, 77, 0.3);
  --mint: #18b875;
  --gold: #f3c34d;
  --red: #d9363e;
  --sky: #4bd6cb;
  --violet: #a681ff;
  --text: #fff3d6;
  --muted: #caa970;
  --shadow: rgba(0, 0, 0, 0.46);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(243, 195, 77, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(243, 195, 77, 0.03) 1px, transparent 1px),
    linear-gradient(115deg, rgba(100, 17, 29, 0.52) 0 16%, transparent 16% 78%, rgba(8, 42, 29, 0.64) 78%),
    var(--bg);
  background-size: 34px 34px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 36px, rgba(243, 195, 77, 0.035) 36px 37px),
    repeating-linear-gradient(0deg, transparent 0 42px, rgba(255, 243, 214, 0.018) 42px 43px);
  opacity: 0.62;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid rgba(243, 195, 77, 0.42);
  background:
    linear-gradient(180deg, rgba(100, 17, 29, 0.96), rgba(18, 13, 10, 0.96)),
    var(--dark-panel);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: #140b08;
  background: var(--gold);
  font-weight: 900;
  flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(243, 195, 77, 0.16), inset 0 -5px 10px rgba(0, 0, 0, 0.2);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 1.2rem + 0.7vw, 2rem);
  line-height: 1.12;
}

.brand p,
.eyebrow,
.site-footer,
.brief-block p {
  color: var(--muted);
}

.brand p {
  margin-top: 5px;
  font-size: 0.92rem;
  color: #e4c98e;
}

.connection {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(243, 195, 77, 0.42);
  border-radius: var(--radius);
  background: rgba(10, 8, 6, 0.72);
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(255, 243, 214, 0.04);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

.dot-online {
  background: var(--mint);
}

.dot-offline {
  background: var(--red);
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(330px, 420px);
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 44px);
}

.arena-panel,
.control-panel,
.table-panel,
.log-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 22px 46px var(--shadow), inset 0 0 0 1px rgba(255, 243, 214, 0.035);
}

.arena-panel,
.table-panel,
.log-panel {
  background:
    linear-gradient(180deg, rgba(25, 16, 13, 0.97), rgba(8, 42, 29, 0.66)),
    var(--dark-panel);
}

.control-panel {
  background:
    linear-gradient(180deg, rgba(58, 7, 16, 0.98), rgba(18, 13, 10, 0.98) 36%, rgba(8, 42, 29, 0.96)),
    var(--panel);
  color: var(--panel-ink);
  padding: 16px;
  border-color: rgba(243, 195, 77, 0.48);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.panel-head.compact {
  padding: 0 0 12px;
}

.table-panel .panel-head,
.log-panel .panel-head {
  padding: 16px 16px 10px;
}

.eyebrow {
  margin-bottom: 5px;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--gold);
}

.round-chip,
.safety-pill,
#teamSynergy,
#lastOutcome {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(243, 195, 77, 0.42);
  background: linear-gradient(180deg, rgba(62, 30, 18, 0.92), rgba(14, 10, 8, 0.96));
  color: var(--text);
  white-space: nowrap;
}

.round-chip span {
  color: var(--muted);
  font-size: 0.82rem;
}

.safety-pill {
  background: #090705;
  color: var(--gold);
  border-color: rgba(243, 195, 77, 0.58);
}

.arena-wrap {
  position: relative;
  margin: 0 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #030403;
  border: 1px solid rgba(243, 195, 77, 0.28);
  aspect-ratio: 5 / 3;
  min-height: 380px;
  box-shadow: inset 0 0 40px rgba(217, 54, 62, 0.16);
}

#arena {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.phase-banner {
  position: absolute;
  left: 14px;
  top: 14px;
  min-width: 132px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(67, 13, 20, 0.9), rgba(12, 8, 6, 0.9));
  color: var(--gold);
  font-weight: 800;
  border: 1px solid rgba(243, 195, 77, 0.3);
}

.scene-readout {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 2px;
  min-width: 150px;
  padding: 9px 10px;
  border: 1px solid rgba(242, 190, 75, 0.36);
  border-radius: var(--radius);
  background: rgba(10, 7, 5, 0.8);
  color: var(--text);
  text-align: right;
}

.scene-readout span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
}

.scene-readout strong {
  color: var(--gold);
  font-size: 0.9rem;
}

.meter-stack {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.meter-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.meter-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.meter-row strong {
  color: var(--text);
}

.meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 243, 214, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--red);
  transition: width 200ms ease;
}

.meter-edge span {
  background: var(--gold);
}

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

.raid-stats div {
  min-height: 72px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(7, 22, 16, 0.62);
  border: 1px solid rgba(243, 195, 77, 0.28);
}

.raid-stats span,
.player-card span,
.log-time,
.amount-row,
.tool-head span {
  color: var(--muted);
}

.raid-stats strong {
  display: block;
  margin-top: 5px;
  font-size: 1.22rem;
}

.identity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(132px, 0.55fr);
  gap: 8px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  color: var(--panel-muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input[type="text"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(243, 195, 77, 0.36);
  border-radius: var(--radius);
  padding: 0 10px;
  background: rgba(5, 7, 5, 0.7);
  color: var(--panel-ink);
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.38);
}

.auto-seat {
  display: grid;
  gap: 3px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid rgba(243, 195, 77, 0.34);
  border-radius: var(--radius);
  background: rgba(7, 42, 29, 0.5);
  color: var(--panel-ink);
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.26);
}

.auto-seat span {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.auto-seat strong {
  font-size: 0.88rem;
  line-height: 1.2;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.mode-button,
.action-grid button,
.horse-button {
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid rgba(243, 195, 77, 0.34);
  background: linear-gradient(180deg, rgba(28, 18, 12, 0.96), rgba(9, 8, 6, 0.96));
  color: var(--panel-ink);
  font-weight: 850;
}

.mode-button.is-active {
  background: linear-gradient(180deg, rgba(243, 195, 77, 0.96), rgba(169, 111, 29, 0.96));
  color: #130b07;
  border-color: rgba(255, 235, 170, 0.74);
}

.tool-block,
.horse-block,
.brief-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(243, 195, 77, 0.24);
}

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

.tool-head strong {
  font-size: 1.14rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--red);
}

.amount-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  color: var(--panel-muted);
  font-size: 0.9rem;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.action-grid button {
  display: grid;
  justify-items: start;
  gap: 5px;
  min-height: 104px;
  padding: 11px;
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255, 243, 214, 0.04);
}

.action-grid button:hover,
.horse-button:hover,
.mode-button:hover {
  filter: brightness(0.96);
}

.action-grid small {
  color: var(--panel-muted);
  line-height: 1.25;
}

.action-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: #120d0a;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.horse-list {
  display: grid;
  gap: 8px;
}

.horse-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
}

.horse-button.is-selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(100, 17, 29, 0.98), rgba(35, 12, 8, 0.98));
}

.horse-lane {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sky);
  color: #07110f;
  font-weight: 900;
}

.horse-name {
  overflow-wrap: anywhere;
}

.horse-meta {
  color: var(--panel-muted);
  font-size: 0.82rem;
}

.brief-block ol {
  margin: 8px 0 8px;
  padding-left: 22px;
  color: var(--panel-ink);
}

.brief-block li + li {
  margin-top: 5px;
}

.brief-block p {
  color: var(--panel-muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.below-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 0 clamp(16px, 4vw, 44px) 18px;
}

.player-list,
.log-list {
  display: grid;
  gap: 9px;
  padding: 0 16px 16px;
}

.player-card,
.log-item {
  border-radius: var(--radius);
  border: 1px solid rgba(243, 195, 77, 0.24);
  background: rgba(10, 14, 10, 0.68);
}

.player-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 12px;
}

.player-name {
  overflow-wrap: anywhere;
  font-weight: 850;
}

.player-card strong {
  color: var(--gold);
}

.role-pill {
  min-width: 70px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(24, 184, 117, 0.18);
  color: var(--mint);
  text-align: center;
  font-size: 0.82rem;
}

.log-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 9px;
  padding: 10px 12px;
}

.log-text {
  overflow-wrap: anywhere;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  padding: 8px 16px 24px;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 1040px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: -1;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .connection {
    width: 100%;
    justify-content: space-between;
  }

  .app-grid,
  .below-grid {
    padding-left: 12px;
    padding-right: 12px;
  }

  .arena-wrap {
    min-height: 260px;
    margin: 0 12px;
  }

  .scene-readout {
    min-width: 118px;
    right: 10px;
    bottom: 10px;
    padding: 7px 8px;
  }

  .panel-head {
    padding: 12px;
  }

  .meter-row,
  .raid-stats,
  .below-grid {
    grid-template-columns: 1fr;
  }

  .identity-row {
    grid-template-columns: 1fr 1fr;
  }

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

  .action-grid button {
    min-height: 74px;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: center;
  }

  .action-grid small {
    grid-column: 2;
  }

  .player-card {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .role-pill {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

@media (max-width: 440px) {
  .identity-row,
  .mode-tabs {
    grid-template-columns: 1fr;
  }

  .horse-button {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .horse-meta {
    grid-column: 2;
  }
}

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