:root {
  --bg: #e9eee9;
  --ink: #1f2622;
  --muted: #66736a;
  --panel: rgba(255, 253, 247, 0.94);
  --line: #cfd7cc;
  --accent: #315c48;
  --accent-2: #9b5a38;
  --gold: #b78932;
  --danger: #a53f3f;
  --shadow: 0 14px 32px rgba(35, 43, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overscroll-behavior-y: auto;
}

body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(49, 92, 72, 0.1) 1px, transparent 1px),
    linear-gradient(180deg, #dfe8e3 0%, var(--bg) 45%, #ece3d4 100%);
  background-size: 34px 34px, auto;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid rgba(25, 36, 31, 0.22);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: #263b32;
  color: #fffaf0;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: #fff;
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: 22rem minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 0 minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar {
  padding: 0;
  border: 0;
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.96);
  overflow: hidden;
}

.sidebar-scroll {
  height: 100%;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.panel,
.zone-panel {
  margin-bottom: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel h1,
.panel h2,
.zone-panel h2 {
  margin: 0 0 0.6rem;
}

.panel-title-row,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stack,
.meta-block {
  display: grid;
  gap: 0.45rem;
}

.mini-button {
  min-width: 2.1rem;
  padding: 0.4rem 0.6rem;
}

.hint,
.empty-text {
  color: var(--muted);
  font-size: 0.92rem;
}

.hidden {
  display: none;
}

.table-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0.7rem;
  overflow: hidden;
}

.show-panel-button {
  position: static;
  min-width: 2.1rem;
  padding: 0.4rem 0.6rem;
}

.tribes-layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: 0.55rem;
  height: 100%;
  min-height: 0;
  min-width: 0;
}

.play-rail {
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.play-rail-scroll {
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.play-rail-scroll > .zone-panel {
  flex: 0 0 200px;
  margin-bottom: 0;
}

.play-rail-scroll > .status-panel {
  flex-basis: 100px;
}

.rail-toggle-slot {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  min-height: 2.1rem;
}

.zone-panel {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.status-panel,
.selected-land-panel,
.market-panel,
.conflict-panel {
  min-height: 0;
}

.conflict-panel {
  display: grid;
  align-content: start;
  gap: 0.45rem;
}

.conflict-panel button,
.conflict-panel select {
  margin: 0;
}

#status {
  white-space: pre-line;
  line-height: 1.35;
}

.selected-land {
  display: grid;
  gap: 0.35rem;
}

.selected-land-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.selected-land-scroll {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 0.65rem;
  padding-right: 0.2rem;
}

.selected-land p {
  margin: 0;
  color: var(--muted);
}

.land-actions {
  display: grid;
  gap: 0.45rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.land-actions h3 {
  margin: 0;
  font-size: 1rem;
}

.land-actions button,
.land-actions select {
  margin: 0;
}

.board-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.5rem;
  min-width: 0;
  min-height: 0;
}

.player-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.45rem;
  min-height: 0;
}

.player-chip {
  display: grid;
  grid-template-rows: repeat(3, 1.15rem);
  gap: 0.18rem;
  min-width: 0;
  min-height: 4.25rem;
  max-height: 4.25rem;
  padding: 0.55rem;
  border: 2px solid var(--player-color, var(--line));
  border-radius: 8px;
  background: #fffdf8;
  font-size: 0.88rem;
  overflow: auto;
  scrollbar-width: thin;
}

.player-chip.active {
  box-shadow: 0 0 0 3px rgba(183, 137, 50, 0.28);
}

.player-chip span {
  color: var(--muted);
}

.player-chip strong,
.player-chip span {
  display: block;
  min-width: max-content;
  white-space: nowrap;
  line-height: 1.15rem;
}

.board-grid {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: clamp(0.22rem, 0.5vw, 0.45rem);
}

.board-cell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  align-items: start;
  gap: 0.18rem;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: clamp(0.3rem, 0.7vw, 0.55rem);
  background: #fbf6e8;
  color: var(--ink);
  text-align: left;
  overflow: hidden;
}

.board-cell.owned {
  border-color: var(--owner);
  box-shadow: inset 0 -0.35rem 0 var(--owner);
}

.board-cell.hidden-land {
  background:
    linear-gradient(135deg, rgba(49, 92, 72, 0.96), rgba(87, 73, 48, 0.92)),
    #315c48;
  color: #fffaf0;
}

.board-cell.contested {
  outline: 3px solid var(--danger);
}

.board-cell.selected {
  box-shadow: 0 0 0 3px var(--gold), inset 0 -0.35rem 0 var(--owner, transparent);
}

.cell-label {
  font-size: 0.75rem;
  color: currentColor;
  opacity: 0.75;
}

.board-cell strong {
  min-width: 0;
  font-size: clamp(0.72rem, 1.1vw, 1rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.board-cell small,
.board-cell i {
  min-width: 0;
  font-size: clamp(0.62rem, 0.9vw, 0.82rem);
  color: currentColor;
  opacity: 0.82;
  overflow-wrap: anywhere;
}

.market-list {
  display: grid;
  gap: 0.45rem;
}

.market-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.18rem 0.5rem;
  align-items: start;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.market-card button {
  grid-row: span 4;
  align-self: center;
  padding: 0.45rem 0.55rem;
}

.market-card strong,
.market-card span,
.market-card p {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.market-card span,
.market-card p {
  color: var(--muted);
  font-size: 0.84rem;
}

.log-list {
  display: grid;
  gap: 0.35rem;
  max-height: 18rem;
  overflow: auto;
}

.log-entry {
  padding: 0.45rem 0.55rem;
  border: 1px solid #e5dfd3;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 920px) {
  html,
  body {
    height: 100%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .board-grid {
    gap: 0.2rem;
  }
}
