:root {
  color-scheme: dark;
  --bg: #121316;
  --panel: #1b1d22;
  --panel-soft: #23262d;
  --line: #343843;
  --text: #f3f4f6;
  --muted: #aab0bd;
  --gold: #f2b84b;
  --blue: #38bdf8;
  --danger: #ef4444;
  --positive: #34d399;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(242, 184, 75, 0.08), transparent 34%),
    linear-gradient(225deg, rgba(56, 189, 248, 0.07), transparent 38%),
    var(--bg);
  color: var(--text);
}

button {
  border: 1px solid #525866;
  border-radius: 6px;
  background: #2b303a;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
}

input {
  width: 100%;
  border: 1px solid #525866;
  border-radius: 6px;
  background: #111827;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  min-height: 42px;
  padding: 0 12px;
}

input:focus {
  border-color: var(--gold);
  outline: none;
}

button:hover:not(:disabled) {
  border-color: var(--gold);
  background: #353b47;
}

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

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

.app-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

.topbar h1 {
  font-size: clamp(24px, 3vw, 38px);
  font-weight: 900;
  letter-spacing: 0;
}

.topbar p,
.panel-header p,
.hint,
.codex-card p,
.codex-card small,
.buyer span {
  color: var(--muted);
}

.money-card {
  min-width: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 16px;
  text-align: right;
}

.money-card span,
.current-bid span,
.settlement-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.money-card strong,
.current-bid strong {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 26px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(520px, 680px) minmax(330px, 380px);
  gap: 16px;
  align-items: start;
  justify-content: center;
}

.warehouse-panel,
.auction-panel,
.codex-panel,
.venue-screen,
.family-screen,
.game-over-screen,
.section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 29, 34, 0.96);
}

.warehouse-panel,
.auction-panel,
.codex-panel,
.venue-screen,
.family-screen,
.game-over-screen {
  padding: 14px;
}

.warehouse-panel {
  grid-column: 2;
  min-height: 640px;
}

.auction-panel {
  grid-column: 3;
  min-height: 640px;
}

.venue-screen,
.family-screen,
.game-over-screen {
  margin-bottom: 16px;
}

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

.panel-header.compact {
  align-items: start;
}

.panel-header h2 {
  font-size: 20px;
}

.ghost-button {
  min-height: 36px;
  background: transparent;
}

.warehouse-frame {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #454b57;
  border-radius: 8px;
  background: #0f1115;
}

.warehouse-svg {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
}

.warehouse-svg.aiming {
  cursor: none;
}

.tool-cursor {
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.55));
}

.tool-row,
.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

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

.stop-clock-button {
  border-color: var(--gold);
  background: linear-gradient(#fffdf4, #d7c5a0);
  color: #462813;
  box-shadow: inset 0 0 0 2px #8b5e2b;
  font-size: 16px;
}

.tool-row button span {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  min-height: 22px;
  margin-left: 6px;
  border-radius: 999px;
  background: #111827;
  color: var(--gold);
  font-size: 12px;
}

.tool-row button.selected {
  border-color: var(--blue);
  background: #123044;
}

.hint {
  min-height: 22px;
  margin-top: 10px;
  font-size: 13px;
}

.start-venue-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.venue-button,
.start-venue-card {
  display: grid;
  gap: 4px;
  height: auto;
  min-height: 82px;
  padding: 8px;
  text-align: left;
}

.start-venue-card {
  min-height: 148px;
  align-content: start;
  padding: 12px;
}

.venue-button strong,
.start-venue-card strong {
  color: var(--text);
  font-size: 13px;
}

.venue-button span,
.venue-button small,
.start-venue-card span,
.start-venue-card small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.start-venue-card strong {
  font-size: 17px;
}

.start-venue-card span {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.venue-button.selected,
.start-venue-card.selected {
  border-color: var(--gold);
  background: #241f13;
}

.debt-pill {
  min-width: 180px;
  border: 1px solid #57472b;
  border-radius: 8px;
  background: #241f13;
  padding: 10px 12px;
  text-align: right;
}

.debt-pill span,
.game-over-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.debt-pill strong,
.game-over-stats strong {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 22px;
}

.family-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
}

.family-member-list,
.family-expense-list {
  display: grid;
  gap: 8px;
}

.family-member,
.family-expense,
.family-total,
.game-over-stats div {
  border: 1px solid #343843;
  border-radius: 7px;
  background: #171a20;
  padding: 10px;
}

.family-member {
  display: grid;
  gap: 3px;
}

.family-member span,
.family-member small {
  color: var(--muted);
  font-size: 13px;
}

.family-expense,
.family-total {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.family-expense strong,
.family-total strong {
  color: var(--gold);
}

.family-total {
  margin-top: 10px;
  border-color: var(--gold);
}

.family-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

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

.auction-panel {
  display: grid;
  gap: 12px;
}

.current-bid,
.section-card {
  padding: 14px;
}

.current-bid {
  border: 1px solid #4b5563;
  border-radius: 8px;
  background: linear-gradient(135deg, #5a251d 0%, #6a3126 50%, #51231c 50%, #4a2019 100%);
  overflow: hidden;
  position: relative;
}

.current-bid p {
  margin-top: 10px;
  color: #f0d4b6;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.auction-clock-face {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 330px;
  border: 2px solid #9d6b38;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 233, 184, 0.08) 0 34%, transparent 35%),
    radial-gradient(circle at 50% 50%, rgba(255, 220, 150, 0.07) 0 62%, transparent 63%),
    linear-gradient(90deg, rgba(39, 16, 17, 0.14) 0 50%, rgba(255, 209, 153, 0.08) 50% 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 210, 128, 0.12);
}

.auction-clock-face::before,
.auction-clock-face::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(230, 174, 95, 0.2);
  border-radius: 16px;
  pointer-events: none;
}

.auction-clock-face::after {
  inset: 30px;
  border-radius: 50%;
  border-color: rgba(123, 65, 36, 0.42);
}

.clock-dial {
  position: relative;
  width: min(250px, 76%);
  aspect-ratio: 1;
  border: 8px solid #c9924c;
  border-radius: 50%;
  background:
    radial-gradient(circle at 45% 43%, rgba(255, 255, 255, 0.08), transparent 30%),
    linear-gradient(90deg, rgba(69, 27, 25, 0.8) 0 50%, rgba(116, 58, 45, 0.72) 50% 100%);
  box-shadow:
    0 0 0 4px #6d3a24,
    0 14px 30px rgba(24, 12, 10, 0.38),
    inset 0 0 30px rgba(18, 9, 9, 0.45);
}

.clock-dial::before {
  content: "";
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  border: 22px solid rgba(125, 62, 50, 0.28);
}

.clock-dial::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -6%;
  bottom: -6%;
  width: 2px;
  background: rgba(223, 168, 92, 0.64);
  transform: translateX(-50%);
}

.clock-glass {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  background: linear-gradient(128deg, transparent 0 36%, rgba(235, 250, 255, 0.22) 37% 55%, transparent 56% 100%);
  pointer-events: none;
}

.clock-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 45%;
  border-radius: 999px;
  background: linear-gradient(#f6d6a2, #9f6436);
  transform: translate(-50%, -100%) rotate(0deg);
  transform-origin: 50% 100%;
  box-shadow: 0 0 0 1px #5d321f, 0 2px 8px rgba(0, 0, 0, 0.36);
  z-index: 2;
}

.clock-needle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -10px;
  width: 15px;
  height: 15px;
  border-radius: 50% 50% 50% 0;
  background: #f4c37b;
  transform: translateX(-50%) rotate(-30deg);
}

.clock-center {
  position: absolute;
  left: 50%;
  top: 52%;
  display: grid;
  gap: 8px;
  width: min(150px, 72%);
  transform: translate(-50%, -42%);
  z-index: 3;
}

.clock-center span {
  color: #f3dec6;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.clock-center strong {
  display: block;
  min-height: 43px;
  border: 3px solid #b77b34;
  border-radius: 8px;
  background:
    linear-gradient(90deg, #dccca5 0 14%, #bfb28f 14% 15%, #dccca5 15% 31%, #bfb28f 31% 32%, #dccca5 32% 48%, #bfb28f 48% 49%, #dccca5 49% 65%, #bfb28f 65% 66%, #dccca5 66% 82%, #bfb28f 82% 83%, #dccca5 83% 100%);
  box-shadow: inset 0 0 0 2px #765229, 0 3px 0 rgba(48, 26, 14, 0.45);
  color: #1e1a15;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  line-height: 37px;
  text-align: center;
  letter-spacing: 0;
}

.clock-center .stop-clock-button {
  min-height: 38px;
  padding: 0 10px;
}

.clock-price-label {
  position: absolute;
  color: #ecd2bc;
  font-size: 24px;
  font-weight: 800;
  text-shadow: 0 2px 1px rgba(30, 12, 10, 0.5);
  z-index: 2;
}

.clock-price-max {
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
}

.clock-price-mid {
  left: 50%;
  bottom: 11px;
  transform: translateX(-50%);
}

.clock-price-floor {
  left: 14px;
  top: 46%;
}

.clock-ornament {
  position: absolute;
  width: 58px;
  height: 58px;
  border-color: #b7834f;
  opacity: 0.58;
}

.clock-ornament.top-left {
  left: 18px;
  top: 16px;
  border-left: 4px solid;
  border-top: 4px solid;
  border-radius: 28px 0 0 0;
}

.clock-ornament.top-right {
  right: 18px;
  top: 16px;
  border-right: 4px solid;
  border-top: 4px solid;
  border-radius: 0 28px 0 0;
}

.clock-ornament.bottom-left {
  left: 18px;
  bottom: 16px;
  border-left: 4px solid;
  border-bottom: 4px solid;
  border-radius: 0 0 0 28px;
}

.clock-ornament.bottom-right {
  right: 18px;
  bottom: 16px;
  border-right: 4px solid;
  border-bottom: 4px solid;
  border-radius: 0 0 28px 0;
}

.danger-button {
  border-color: #7f1d1d;
  background: #451a1a;
}

.section-card h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

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

.buyer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 1px solid #343843;
  border-radius: 6px;
  background: #171a20;
  padding: 10px;
}

.buyer div:first-child {
  display: grid;
  gap: 2px;
}

.buyer.inactive {
  opacity: 0.48;
}

.buyer.thinking {
  border-color: var(--gold);
  background: #241f13;
}

.buyer-bid {
  color: var(--gold);
  font-weight: 800;
  white-space: nowrap;
}

.log-card ol {
  display: grid;
  gap: 7px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding-left: 20px;
  color: #d9dde6;
  font-size: 13px;
}

.warehouse-log-card {
  margin-top: 12px;
}

.warehouse-log-card ol {
  max-height: 150px;
}

.round-results {
  display: grid;
  gap: 8px;
}

.round-result {
  border: 1px solid #343843;
  border-radius: 6px;
  background: #171a20;
  padding: 9px;
}

.round-result strong {
  display: block;
  margin-bottom: 6px;
  color: var(--gold);
}

.round-result div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.round-result span {
  border: 1px solid #3d4450;
  border-radius: 999px;
  padding: 3px 7px;
  color: #cdd3df;
  font-size: 12px;
}

.round-result .round-winner {
  border-color: var(--gold);
  color: var(--gold);
}

.codex-panel {
  grid-column: 1;
  grid-row: 1;
  min-height: 640px;
  max-height: none;
  overflow: hidden;
}

.codex-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 760px;
  overflow: auto;
  padding-right: 4px;
}

.codex-card {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid #3f4551;
  border-left-width: 5px;
  border-radius: 7px;
  background: #171a20;
  padding: 12px;
}

.codex-preview {
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  border: 1px solid #303641;
  border-radius: 6px;
  background: #10141b;
  overflow: hidden;
}

.codex-preview-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.codex-preview-locked {
  color: #6b7280;
  font-size: 44px;
  font-weight: 900;
}

.codex-card-body {
  min-width: 0;
}

.codex-card.locked {
  opacity: 0.52;
}

.codex-title {
  display: grid;
  gap: 8px;
  margin-bottom: 4px;
}

.codex-title span {
  color: var(--muted);
  font-size: 12px;
}

.codex-card p,
.codex-card small {
  overflow-wrap: anywhere;
}

.quality-white {
  border-color: #d4d4d8;
}

.quality-blue {
  border-color: #38bdf8;
}

.quality-purple {
  border-color: #a78bfa;
}

.quality-gold {
  border-color: #f2b84b;
}

dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid #525866;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

#settlementBody {
  padding: 16px;
}

#nextAuctionButton {
  width: calc(100% - 32px);
  margin: 0 16px 16px;
}

.settlement-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.settlement-stats div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #171a20;
  padding: 10px;
}

.settlement-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--danger);
}

.settlement-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.settlement-items li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid #343843;
  border-radius: 6px;
  padding: 8px 10px;
  background: #171a20;
}

.settlement-item-detail small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.item-money {
  display: grid;
  gap: 3px;
  text-align: right;
}

.item-money em {
  font-style: normal;
  font-weight: 800;
  font-size: 12px;
}

.settlement-items strong {
  color: var(--gold);
  white-space: nowrap;
}

.settlement-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.settlement-review {
  margin: 16px 0;
  border: 1px solid #4b5563;
  border-radius: 8px;
  background: #141820;
  padding: 12px;
}

.settlement-review-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.settlement-review-list {
  border: 1px solid #343843;
  border-radius: 7px;
  background: #171a20;
  padding: 10px;
}

.settlement-review-list h4 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 14px;
}

.settlement-review-list ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.settlement-review-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #d5d9e2;
  font-size: 13px;
}

.settlement-review-list strong {
  color: var(--gold);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.settlement-inline {
  border-color: var(--gold);
  background: #211f19;
}

.settlement-inline #settlementInlineBody {
  margin-top: 12px;
}

.settlement-inline #nextAuctionInlineButton {
  width: 100%;
  margin-top: 12px;
}

.settlement-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: #241f13;
  padding: 12px;
}

.settlement-banner strong {
  display: block;
  color: var(--gold);
  font-size: 17px;
}

.settlement-banner p {
  margin-top: 4px;
  color: #d8d1c2;
  font-size: 13px;
}

.settlement-banner button {
  white-space: nowrap;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: transparent;
  pointer-events: auto;
}

.tutorial-spotlight {
  position: fixed;
  left: var(--tutorial-x, 24px);
  top: var(--tutorial-y, 24px);
  width: var(--tutorial-w, 220px);
  height: var(--tutorial-h, 120px);
  border: 3px solid var(--gold);
  border-radius: 10px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.72),
    0 0 24px rgba(242, 184, 75, 0.65);
  pointer-events: none;
  transition: left 180ms ease, top 180ms ease, width 180ms ease, height 180ms ease;
}

.tutorial-card {
  position: fixed;
  left: var(--tutorial-card-x, 24px);
  top: var(--tutorial-card-y, 24px);
  width: min(360px, calc(100vw - 28px));
  border: 1px solid #6b7280;
  border-radius: 8px;
  background: #171a20;
  color: var(--text);
  padding: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  transition: left 180ms ease, top 180ms ease;
}

.tutorial-card.intro {
  display: grid;
  align-content: center;
  width: min(760px, calc(100vw - 48px));
  min-height: min(460px, calc(100vh - 48px));
  padding: 34px 42px;
  border-color: var(--gold);
  background:
    linear-gradient(135deg, rgba(242, 184, 75, 0.08), transparent 45%),
    #171a20;
}

.tutorial-card.intro span {
  display: none;
}

.tutorial-card.intro h3 {
  margin-bottom: 18px;
  color: var(--gold);
  font-size: 34px;
}

.tutorial-card.intro p {
  max-width: 640px;
  font-size: 17px;
  line-height: 1.8;
}

.tutorial-card.intro .tutorial-actions {
  width: min(420px, 100%);
  margin-top: 28px;
}

.tutorial-card span {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
}

.tutorial-card h3 {
  margin-bottom: 8px;
  font-size: 19px;
}

.tutorial-card p {
  color: #d5d9e2;
  line-height: 1.55;
}

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

@media (max-width: 1280px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
  }

  .start-venue-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .warehouse-panel {
    grid-column: 1;
  }

  .auction-panel {
    grid-column: 2;
  }

  .codex-panel {
    grid-column: 1 / -1;
    grid-row: auto;
    min-height: 0;
  }

  .codex-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 500px;
  }

  .codex-card {
    grid-template-columns: 128px minmax(0, 1fr);
  }

  .codex-preview {
    width: 128px;
    height: 128px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .money-card {
    text-align: left;
  }

  .game-layout,
  .tool-row,
  .actions,
  .start-venue-list,
  .family-layout,
  .family-actions,
  .game-over-stats,
  .codex-list,
  .settlement-stats,
  .settlement-items,
  .settlement-review-lists {
    grid-template-columns: 1fr;
  }

  .settlement-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .auction-clock-face {
    min-height: 300px;
  }

  .clock-dial {
    width: min(230px, 74vw);
  }

  .clock-price-label {
    font-size: 19px;
  }

  .clock-price-floor {
    left: 8px;
  }

  .clock-price-max {
    top: 8px;
  }

  .warehouse-panel,
  .auction-panel,
  .codex-panel {
    grid-column: auto;
    grid-row: auto;
    padding: 10px;
  }

  .codex-card {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .codex-preview {
    width: 120px;
    height: 120px;
  }
}
