:root {
  --bg: #f6efe4;
  --panel: #fffaf0;
  --line: #b98c3c;
  --ink: #2e2418;
  --muted: #6f6659;
  --tile: #efe1c8;
  --river: #b9d7ff;
  --hex-w: 80px;
  --hex-h: 92px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 30px;
}

.online-badge {
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
  background: #fff;
}

.scorebar {
  display: flex;
  gap: 8px;
  margin: 10px 0 12px;
}

.tab-btn {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #efe3cc;
  color: #4f3d1f;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
}

.tab-btn.is-active {
  background: #7f5ae0;
  border-color: #7f5ae0;
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 13px;
}

.pill.plain { background: var(--tile); }
.pill.river { background: var(--river); }

.layout {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 10px;
}

.panel h2,
.panel h3 {
  margin: 0 0 8px 0;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 220px));
  gap: 8px;
  margin-bottom: 8px;
}

.field {
  display: grid;
  gap: 4px;
  font-weight: 700;
  font-size: 12px;
}

.field select,
.input {
  border: 1px solid #d2c3a8;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.btn {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #efe3cc;
  color: #4f3d1f;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-strip {
  display: block;
  margin-bottom: 10px;
}

.setup-status-inline {
  margin-top: 8px;
  margin-bottom: 0;
}

.strip-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: nowrap;
}

.strip-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
}

.day-track-wrap {
  flex: 1 1 auto;
  min-width: 320px;
}

.day-track {
  display: grid;
  grid-template-columns: repeat(7, minmax(38px, 1fr));
  gap: 6px;
}

.day-cell {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #efe3cc;
  text-align: center;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
}

.day-cell.is-active {
  background: #e33b3b;
  border-color: #e33b3b;
  color: #fff;
}

.honor-inline {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.honor-card {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
}

.honor-card strong {
  font-size: 18px;
}

.status {
  border: 1px solid #d2c3a8;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  margin-bottom: 10px;
  font-size: 14px;
}

.players {
  display: grid;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d2c3a8;
  border-radius: 8px;
  padding: 6px;
  background: #fff;
}

.player-row img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.help {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.board-zone {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  min-height: 700px;
  padding: 8px;
}

.board-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
  border-radius: 10px;
  background: #fdf8ee;
  border: 1px solid #d2c3a8;
}

.board {
  position: relative;
  min-width: 900px;
  min-height: 760px;
  background: #f8f1e5;
}

.board.plateau-bg {
  background-image: url('../data/plateau.jpg');
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% 100%;
}

.hex {
  position: absolute;
  width: var(--hex-w);
  height: var(--hex-h);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border: 0;
  background: #efe1c8;
  display: grid;
  place-items: center;
  box-shadow: none;
  cursor: pointer;
  transition: transform 120ms ease;
}

.hex:active {
  transform: scale(0.98);
}

.hex.terrain-green {
  background: #5ddf42;
}

.hex.terrain-yellow {
  background: #e0de91;
}

.hex.river {
  background: #b9d7ff;
}

.hex.order-dark {
  background: #3e3e41;
}

.hex.order-blue {
  background: #5a64db;
}

.order-dots {
  position: absolute;
  top: 16px;
  display: flex;
  gap: 10px;
  z-index: 3;
}

.order-dots span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #c7c7c7;
  box-shadow: 0 0 0 1px rgba(0,0,0,.18);
}

.hex-label {
  font-size: 12px;
  color: #16120d;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
  pointer-events: none;
  text-align: center;
  transform: none;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  gap: 2px;
}

.hex-id {
  font-weight: 700;
  font-size: 12px;
}

.hex-qr {
  font-weight: 600;
  font-size: 11px;
  opacity: 0.9;
}

.hex.order-dark .hex-label,
.hex.order-blue .hex-label {
  color: #f2efe8;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
}

.hex.is-blinking {
  animation: hexBlink 0.7s infinite;
}

.hex.is-order-selected {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.95), 0 0 0 6px rgba(255, 60, 60, 0.95);
  z-index: 6;
}

.hex.is-target-highlight {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.95), 0 0 0 6px rgba(255, 60, 60, 0.95);
  z-index: 5;
}

.hex.is-target-highlight::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: inherit;
  background: rgba(255, 0, 0, 0.28);
  pointer-events: none;
}

.hex.order-preview-blink {
  animation: orderPreviewBlink 0.5s linear 5;
}

@keyframes orderPreviewBlink {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.55);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes hexBlink {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.45) drop-shadow(0 0 6px rgba(255, 255, 255, 0.9));
  }
  100% {
    filter: brightness(1);
  }
}

.piece-stack {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.piece-token {
  width: 30px;
  height: 30px;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.25));
}

.piece-token.building {
  width: 34px;
  height: 34px;
}

@media (max-width: 980px) {
  .layout {
    flex-direction: column;
  }
  .setup-grid {
    grid-template-columns: 1fr;
  }
  .strip-row {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .day-track {
    grid-template-columns: repeat(7, 1fr);
  }
  .honor-inline {
    width: 100%;
    flex-wrap: wrap;
  }
}

.setup-preview {
  margin-top: 8px;
  border: 1px solid #d2c3a8;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.setup-preview-img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border: 1px solid #d2c3a8;
  border-radius: 8px;
  background: #fffaf0;
  flex: 0 0 auto;
}

.setup-preview-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.turn-engine {
  margin-top: 8px;
  border: 1px solid #d2c3a8;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

.turn-engine-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.turn-engine-status {
  margin-bottom: 8px;
}

.order-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.order-stack {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  z-index: 4;
}

.order-chip {
  min-width: 24px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  background: rgba(255, 255, 255, 0.92);
  font-size: 10px;
  font-weight: 700;
  color: #2b2014;
  padding: 2px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.order-chip.is-hidden {
  background: rgba(100, 100, 100, 0.82);
  color: #fff;
}

@media (max-width: 980px) {
  .order-controls {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}
