:root {
  --ink: #1f1209;
  --paper: #efe3bf;
  --panel: #f6efd5;
  --panel-strong: #e5d8b0;
  --leaf: #9dcb64;
  --mist: #8ecfc9;
  --gold: #f3d06c;
  --ember: #ef9a4c;
  --red: #f05f5f;
  --stone: #d4c9a6;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Chakra Petch", sans-serif;
  color: var(--ink);
  background-color: #2c4a2d;
}

.page-wrap {
  width: min(1450px, 96vw);
  margin: 0 auto;
  padding: 14px 0 20px;
}

h1,
h2,
h3,
button,
strong,
kbd {
  font-family: "Bungee", sans-serif;
  font-weight: 400;
}

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

.brutal-card {
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 8px 8px 0 #140c06;
}

.topbar {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background-color: var(--panel);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 66px;
  height: 66px;
  border: 4px solid var(--ink);
  border-radius: 12px;
  background: var(--leaf);
  padding: 2px;
  overflow: hidden;
  box-shadow: 4px 4px 0 var(--ink);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform: scale(1.08) translateY(2px);
}

.brand-block h1 {
  font-size: 2.1rem;
  letter-spacing: 0.03em;
  line-height: 1;
}

.brand-block p {
  margin-top: 4px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #4b3a1a;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  min-width: 118px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  padding: 7px 10px;
  box-shadow: 4px 4px 0 var(--ink);
}

.chip span {
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
}

.chip strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
}

.chip-online {
  background: var(--mist);
}

.chip-balance {
  background: var(--leaf);
}

.chip-round {
  background: var(--gold);
}

.layout-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(300px, 340px) 1fr minmax(280px, 320px);
  gap: 12px;
  align-items: start;
}

.control-card,
.side-card,
.arena-card {
  padding: 12px;
}

.control-card {
  position: relative;
}

.control-card h2,
.arena-card h2,
.side-card h2,
.side-card h3 {
  margin-bottom: 10px;
  font-size: 1.14rem;
}

.control-card label {
  display: block;
  margin: 10px 0 6px;
  font-size: 0.82rem;
  font-weight: 700;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inline-info-btn {
  margin-top: 8px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--mist);
  color: var(--ink);
  font-family: "Bungee", sans-serif;
  font-size: 0.64rem;
  height: 30px;
  min-width: 64px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.inline-info-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.risk-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.risk-btn {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  height: 40px;
  font-size: 0.86rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.risk-btn:active,
.quick-row button:active,
.action-btn:active,
.step-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.risk-btn.active[data-risk="low"] {
  background: var(--leaf);
}

.risk-btn.active[data-risk="medium"] {
  background: var(--gold);
}

.risk-btn.active[data-risk="high"] {
  background: var(--red);
}

.risk-info-popup {
  position: absolute;
  top: 92px;
  left: 12px;
  right: 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 6px 6px 0 #140c06;
  padding: 8px;
  z-index: 12;
}

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

.risk-info-head h3 {
  font-size: 0.82rem;
}

.risk-info-close {
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  height: 30px;
  min-width: 32px;
  cursor: pointer;
  font-family: "Bungee", sans-serif;
  font-size: 0.58rem;
  box-shadow: 2px 2px 0 var(--ink);
}

.risk-info-close:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

.risk-info-item {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  padding: 6px;
  margin-bottom: 6px;
}

.risk-info-item:last-child {
  margin-bottom: 0;
}

.risk-info-item h4 {
  margin: 0 0 3px;
  font-size: 0.72rem;
}

.risk-info-item p {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.25;
  font-weight: 700;
}

.risk-info-item.low {
  background: var(--leaf);
}

.risk-info-item.medium {
  background: var(--gold);
}

.risk-info-item.high {
  background: var(--red);
}

.amount-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
}

.step-btn {
  border: 3px solid var(--ink);
  border-radius: 10px;
  font-size: 1.2rem;
  cursor: pointer;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
}

.amount-input {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #f7f1dc;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

.amount-input span {
  font-size: 1rem;
  font-weight: 700;
}

.amount-input input {
  width: 100%;
  border: none;
  outline: none;
  height: 40px;
  font-size: 1rem;
  background: transparent;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
}

.quick-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-row button {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  height: 36px;
  font-size: 0.72rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

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

.action-btn {
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

.action-btn.primary {
  background: var(--ember);
}

.action-btn.secondary {
  background: var(--mist);
}

.action-btn[disabled] {
  background: #d8d8d8;
  color: #686868;
  cursor: not-allowed;
  box-shadow: 3px 3px 0 var(--ink);
}

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

.metric-box {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #f8f2df;
  padding: 7px 8px;
}

.metric-box span {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
}

.metric-box strong {
  display: block;
  margin-top: 2px;
  font-size: 0.9rem;
}

#multiplierValue {
  color: #0f4f33;
}

#multiplierValue.danger {
  color: #ab222a;
}

.hint {
  margin-top: 10px;
  border: 3px dashed var(--ink);
  border-radius: 10px;
  padding: 8px;
  background: #e8ddb7;
  font-size: 0.82rem;
  font-weight: 700;
}

.arena-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.arena-head p {
  font-size: 0.78rem;
  font-weight: 700;
}

kbd {
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--panel-strong);
  padding: 2px 7px;
  font-size: 0.7rem;
}

.tower-shell {
  position: relative;
  height: 560px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
  background: #121a10;
  box-shadow: inset 0 0 0 4px #ffffff33;
}

#towerCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 20px;
  background: linear-gradient(180deg, rgba(12, 18, 13, 0.24) 0%, rgba(12, 18, 13, 0.7) 100%);
  color: #fff8da;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
  z-index: 5;
}

.start-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.start-overlay h3 {
  font-size: 1.2rem;
}

.start-overlay p {
  font-size: 0.86rem;
  font-weight: 700;
}

.start-overlay-btn {
  justify-self: center;
  min-width: 190px;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: var(--ember);
  color: var(--ink);
  font-family: "Bungee", sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

.start-overlay-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.side-card h3 {
  margin-top: 10px;
}

.session-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.session-grid div {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  padding: 8px;
}

.session-grid span {
  display: block;
  font-size: 0.67rem;
  font-weight: 700;
}

.session-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
}

.history-list {
  margin-top: 8px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #f4ead0;
  min-height: 395px;
  max-height: 395px;
  overflow: auto;
  padding: 6px;
}

.history-item {
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 7px;
  margin-bottom: 6px;
  display: grid;
  gap: 3px;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-item.win {
  background: var(--leaf);
}

.history-item.loss {
  background: #ffd5d8;
}

.history-item span {
  font-size: 0.66rem;
  font-weight: 700;
}

.history-item strong {
  font-size: 0.92rem;
}

.history-item em {
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.howto-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 8, 0.68);
  display: grid;
  place-items: center;
  padding: 14px;
  z-index: 30;
}

.howto-card {
  width: min(560px, 94vw);
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 8px 8px 0 #140c06;
  background: var(--panel);
  padding: 14px;
}

.howto-card h2 {
  font-size: 1.24rem;
  margin-bottom: 8px;
}

.howto-card p {
  font-size: 0.88rem;
  font-weight: 700;
}

.howto-card ul {
  margin: 10px 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 700;
}

.howto-close-btn {
  width: 100%;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: var(--leaf);
  color: var(--ink);
  font-family: "Bungee", sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

.howto-close-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

@media (max-width: 1240px) {
  .layout-grid {
    grid-template-columns: minmax(280px, 330px) 1fr;
  }

  .side-card {
    grid-column: 1 / -1;
  }

  .history-list {
    min-height: 220px;
    max-height: 220px;
  }
}

@media (max-width: 900px) {
  .page-wrap {
    width: min(680px, 94vw);
    padding: 10px 0 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .chip-row {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .chip {
    min-width: 0;
  }

  .layout-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .arena-card {
    order: 1;
  }

  .control-card {
    order: 2;
  }

  .side-card {
    order: 3;
  }

  .tower-shell {
    height: 420px;
  }

  .start-overlay h3 {
    font-size: 1.04rem;
  }

  .start-overlay p {
    font-size: 0.78rem;
  }

  .arena-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .history-list {
    min-height: 170px;
    max-height: 170px;
  }
}
