*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #1a1a1a;
  font-family: Arial, sans-serif;
  user-select: none;
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
  z-index: 0;
}

/* ── LAYOUT SHELL ─────────────────────────────────────────
   Two modes driven by a class on <body>:
     body.landscape  — ui panel left, board fills right
     body.portrait   — ui bar top, board fills below
──────────────────────────────────────────────────────── */

/* LANDSCAPE: left sidebar */
body.landscape #ui {
  position: fixed;
  left: 10px;
  top: 10px;
  width: 360px;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  background: rgba(0,0,0,0.88);
  border-radius: 12px;
  padding: 14px;
  color: white;
  z-index: 100;
}

/* PORTRAIT: top bar, horizontal bank */
body.portrait #ui {
  position: fixed;
  left: 0; top: 0; right: 0;
  width: 100%;
  background: rgba(0,0,0,0.92);
  padding: 8px 10px 6px;
  color: white;
  z-index: 100;
  border-bottom: 1px solid #333;
}

/* ── TITLE ──────────────────────────────────────────────── */
#title {
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 8px;
}

body.portrait #title {
  display: none; /* hide title in portrait to save space */
}

/* ── INFO ───────────────────────────────────────────────── */
#info {
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 8px;
}

body.portrait #info { display: none; }

/* ── BANK ───────────────────────────────────────────────── */

/* Landscape default: column of rows */
#token-bank {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 12px;
}

/* Each PNG row = one horizontal strip */
.bank-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
}

/* Separator line between PNG rows in landscape */
.bank-row + .bank-row {
  border-top: 1px solid rgba(255,255,255,0.15);
  margin-top: 2px;
  padding-top: 5px;
}

/* Portrait: single horizontal scrolling strip */
body.portrait #token-bank {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0;
  margin-bottom: 0;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

body.portrait .bank-row {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 0;
  border-top: none !important;
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* Vertical divider between PNG rows in portrait */
body.portrait .bank-row + .bank-row {
  border-left: 1px solid rgba(255,255,255,0.15);
  margin-left: 4px;
  padding-left: 4px;
}

/* ── TOKEN WRAPPER / ITEM ───────────────────────────────── */
.token-wrapper {
  position: relative;
  width: 54px;
  height: 54px;
  flex-shrink: 0;
}

.token-item {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #2a2a2a;
  cursor: grab;
  transition: 0.12s;
}

body.landscape .token-wrapper { width: 64px; height: 64px; }
body.landscape .token-item    { width: 64px; height: 64px; }

.token-item:hover {
  transform: scale(1.05);
  border-color: white;
}

/* Selected state for touch tap-to-place */
.token-item.touch-selected,
.token-wrapper.touch-selected .token-item {
  border-color: #ffca28;
  box-shadow: 0 0 0 2px #ffca28, 0 0 10px rgba(255,202,40,0.5);
  transform: scale(1.08);
}

.bank-counter {
  position: absolute;
  right: 2px;
  bottom: 2px;
  font-size: 11px;
  background: rgba(0,0,0,0.85);
  padding: 1px 4px;
  border-radius: 6px;
  border: 1px solid #999;
  color: white;
}

/* ── HEX POINT VALUE ROW ────────────────────────────────── */
.hex-points-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  margin-bottom: 6px;
}

.hex-points-label {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  flex: 1;
}

.hex-points-value {
  font-size: 16px;
  font-weight: bold;
  color: #ffca28;
  min-width: 28px;
  text-align: center;
}

.hex-points-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #666;
  border-radius: 6px;
  background: #333;
  color: white;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s;
  flex-shrink: 0;
}

.hex-points-btn:hover  { background: #555; border-color: #ffca28; }
.hex-points-btn:active { background: #ffca28; color: #000; }
#selected-hex-panel {
  margin-top: 10px;
  border-top: 1px solid #444;
  padding-top: 10px;
}

body.portrait #selected-hex-panel { display: none; }

#selected-hex-title {
  margin-bottom: 8px;
  font-weight: bold;
  font-size: 13px;
}

#selected-hex-tokens {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hex-token-row {
  position: relative;
  height: 60px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  transition: 0.12s;
  cursor: pointer;
  overflow: hidden;
}

.hex-token-row:hover { background: rgba(255,255,255,0.15); }
.hex-token-row.selected {
  background: rgba(255,255,180,0.18);
  outline: 2px solid #ffffaa;
}

.hex-token-row canvas {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
}

.hex-token-layer-label {
  position: absolute;
  top: 5px; left: 8px;
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── POPUP ──────────────────────────────────────────────── */
#popup {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: #7a1f1f;
  border: 2px solid #ffaaaa;
  color: white;
  padding: 18px 28px;
  border-radius: 12px;
  font-size: 18px;
  z-index: 999;
  display: none;
  pointer-events: none;
}

/* ── DRAG IMAGE ─────────────────────────────────────────── */
#drag-image-helper {
  position: fixed;
  pointer-events: none;
  z-index: 99999;
  top: -9999px; left: -9999px;
}

/* ── HELP BOX ───────────────────────────────────────────── */
#help-box {
  position: fixed;
  top: 12px; right: 12px;
  width: 280px;
  background: rgba(10, 10, 20, 0.80);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  color: #ddd;
  font-size: 13px;
  line-height: 1.6;
  z-index: 2147483647;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  overflow: hidden;
  transition: max-height 0.3s ease;
  max-height: 44px;
}

/* Portrait: anchor guide to bottom-right, above turn indicator row */
body.portrait #help-box {
  top: auto;
  bottom: 8px;
  right: 8px;
  width: min(280px, calc(100vw - 16px));
}

#help-box.open { max-height: 70vh; }

#help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #fff;
  user-select: none;
}

#help-header:hover { background: rgba(255,255,255,0.06); }

#help-toggle-icon {
  font-size: 16px;
  transition: transform 0.25s;
}

#help-box.open #help-toggle-icon { transform: rotate(180deg); }

#help-content {
  padding: 0 14px 14px;
  max-height: calc(70vh - 44px);
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: 'Georgia', serif;
  color: #ccc;
}

#help-content h3 {
  color: #ffca28;
  font-size: 13px;
  margin: 12px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#help-content p { margin: 0 0 8px; }

#help-content a {
  color: #ffca28;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#help-content a:hover { color: #fff; }

/* ── PLAYER HANDS ───────────────────────────────────────── */
.player-hand {
  position: fixed;
  width: 200px;
  height: 260px;
  background: rgba(0,0,0,0.88);
  border: 3px solid #ffca28;
  border-radius: 12px;
  padding: 10px;
  color: white;
  z-index: 95;
  display: flex;
  flex-direction: column;
}

/* LANDSCAPE: beside the ui panel */
body.landscape #hand-p1 { left: 380px; top: 10px; }
body.landscape #hand-p2 { left: 380px; top: 280px; }

/* PORTRAIT: bottom-left and bottom-right corners */
body.portrait .player-hand {
  width: 46%;
  max-width: 200px;
  height: 160px;
  bottom: 54px; /* above turn indicator */
}
body.portrait #hand-p1 { left: 4px;  bottom: 54px; top: auto; }
body.portrait #hand-p2 { right: 4px; left: auto; bottom: 54px; top: auto; }

.hand-title {
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 13px;
  border-bottom: 1px solid #444;
  padding-bottom: 4px;
}

body.portrait .hand-title { font-size: 11px; margin-bottom: 4px; }

.hand-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  overflow-y: auto;
  flex-grow: 1;
}

/* ── TURN INDICATOR ─────────────────────────────────────── */
/* Portrait: pin to bottom-left, inline with the guide button */
#turn-indicator {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  display: none;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

/* Portrait: anchor to bottom-left so it sits next to the guide box toggle */
body.portrait #turn-indicator {
  left: 8px;
  transform: none;
  bottom: 8px;
  font-size: 12px;
  padding: 5px 12px;
}

#btn-end-turn {
  display: none;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: bold;
  background: #ffca28;
  color: #000;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}

/* ── TOUCH PLACEMENT HINT ───────────────────────────────── */
#touch-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.82);
  border: 1px solid #ffca28;
  color: #ffca28;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
  pointer-events: none;
  display: none;
  text-align: center;
}
