:root {
  --ak-gold: #ffd24a;
  --ak-green: #35e79a;
  --ak-red: #ff6b5f;
  --ak-panel: rgba(11, 25, 33, 0.92);
  --ak-panel-soft: rgba(22, 41, 50, 0.86);
  --ak-line: rgba(179, 205, 211, 0.22);
  --ak-text: #f7f3e8;
  --ak-muted: #aebec5;
}

* { box-sizing: border-box; }

body.alkkagi-game-page {
  min-height: 100vh;
  margin: 0;
  padding: 0 18px 48px;
  color: var(--ak-text);
  background:
    linear-gradient(180deg, rgba(3, 14, 21, 0.78), rgba(3, 13, 19, 0.94)),
    url("../images/backgrounds/main_background.jpg") center / cover fixed;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ak-game-topbar {
  position: sticky;
  top: 0;
  z-index: 1200;
  width: min(1240px, 100%);
  min-height: 58px;
  margin: 0 auto;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
  background: rgba(5, 16, 22, 0.94);
  border: 1px solid var(--ak-line);
  border-top: 0;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
}

.ak-top-actions,
.ak-room-meta,
.ak-user-summary {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ak-room-meta { justify-content: center; font-weight: 750; }
.ak-user-summary { justify-content: flex-end; color: var(--ak-muted); }
.ak-user-summary strong { color: var(--ak-gold); }

.ak-nav-btn,
.ak-control-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  color: var(--ak-text);
  background: #233842;
  border: 1px solid rgba(194, 218, 223, 0.35);
  border-radius: 9px;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ak-nav-btn:hover,
.ak-control-btn:hover { border-color: var(--ak-gold); background: #2d4651; }
.ak-nav-btn.danger { background: #9e3f39; border-color: #d77a73; }

.ak-game-shell {
  width: min(1180px, 100%);
  margin: 22px auto 0;
}

.ak-stage-banner {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(300px, 1.6fr) minmax(210px, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-bottom: 14px;
  background: var(--ak-line);
  border: 1px solid rgba(255, 210, 74, 0.46);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.26), 0 0 30px rgba(255, 204, 51, 0.07);
}

.ak-stage-cell {
  min-height: 94px;
  padding: 15px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--ak-panel);
}

.ak-stage-cell.goal { background: linear-gradient(135deg, rgba(55, 47, 18, 0.97), rgba(19, 31, 33, 0.97)); }
.ak-stage-label { color: var(--ak-muted); font-size: 12px; font-weight: 800; letter-spacing: 0.13em; }
.ak-stage-number { color: var(--ak-gold); font-size: clamp(25px, 3vw, 38px); font-weight: 900; line-height: 1.15; }
.ak-stage-name { margin-top: 2px; color: #fff; font-size: 14px; font-weight: 700; }
.ak-goal-title { margin-top: 4px; color: #fff5c4; font-size: clamp(18px, 2vw, 25px); font-weight: 850; }
.ak-goal-progress { margin-top: 5px; color: #e6d99b; font-size: 13px; }
.ak-stage-metrics { gap: 7px; color: #dae4e7; font-size: 14px; }
.ak-stage-metrics strong { color: #fff; }
.ak-stage-summary { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.ak-player-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  margin: 0 0 14px;
}

.ak-player-card {
  position: relative;
  min-height: 72px;
  padding: 12px 17px 12px 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--ak-panel-soft);
  border: 2px solid transparent;
  border-radius: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.ak-player-card::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #666, #050505 72%);
  border: 2px solid #0b0d0e;
  box-shadow: 0 4px 8px #0009;
}

.ak-player-card.white::before {
  background: radial-gradient(circle at 32% 28%, #fff, #c5cbce 72%);
  border-color: #fff;
}

.ak-player-card.active-turn {
  border-color: var(--ak-green);
  box-shadow: 0 0 0 3px rgba(53, 231, 154, 0.11), 0 0 24px rgba(53, 231, 154, 0.2);
  transform: translateY(-1px);
}

.ak-player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 850; }
.ak-player-count { margin-top: 3px; color: var(--ak-muted); font-size: 13px; }
.ak-vs {
  display: grid;
  place-items: center;
  color: var(--ak-red);
  font-size: 21px;
  font-weight: 950;
  font-style: italic;
}

.ak-play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  gap: 16px;
  align-items: start;
}

.ak-board-panel,
.ak-side-panel,
.ak-item-guide {
  background: var(--ak-panel);
  border: 1px solid var(--ak-line);
  border-radius: 16px;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.25);
}

.ak-board-panel { padding: 12px; }
.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 11px;
  cursor: crosshair;
  background: #07141a;
}

#alkkagiBoard { display: block; width: 100%; height: auto; background: transparent; touch-action: none; }
#itemOverlay { position: absolute; inset: 0; pointer-events: none; }

.ak-side-panel { padding: 18px; }
.ak-panel-heading { margin: 0 0 11px; color: var(--ak-muted); font-size: 12px; letter-spacing: 0.12em; }
.game-status {
  min-height: 68px;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  color: var(--ak-gold);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.45;
}

.ak-error { margin: 0 0 12px; color: #ffaaa1; white-space: pre-line; }
.ak-error:empty { display: none; }
.ak-side-actions { display: grid; gap: 8px; }
.ak-control-btn { width: 100%; }
.ak-side-note { margin: 16px 0 0; color: var(--ak-muted); font-size: 12px; line-height: 1.55; }

.ak-item-guide { margin-top: 16px; padding: 15px 18px; }
.ak-item-guide summary { cursor: pointer; color: #e9eff1; font-weight: 800; }
.item-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; margin-top: 13px; }
.legend-item { min-width: 0; display: flex; gap: 8px; align-items: center; color: #cbd7db; font-size: 13px; }
.legend-item b { color: #fff; }

.alkkagi-item-obj,
.item-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  background-image: url("../images/effects/item_sprite_sheet.gif");
  background-repeat: no-repeat;
  filter: drop-shadow(2px 4px 3px rgba(0, 0, 0, 0.55));
}
.alkkagi-item-emoji { position: absolute; font-size: 30px; filter: drop-shadow(2px 4px 3px #0008); }
.icon_1 { background-position: -3px -9px; background-size: 152px 76px; }
.icon_2 { background-position: -48px -2px; background-size: 186px 64px; }
.icon_3 { background-position: -86px -11px; background-size: 201px 105px; }
.icon_4 { background-position: -120px -11px; background-size: 201px 102px; }
.icon_5 { background-position: -112px -9px; background-size: 147px 94px; }
.icon_6 { background-position: -10px -51px; background-size: 188px 93px; }

#gameOverOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10001;
  padding: 20px;
  align-items: center;
  justify-content: center;
  background: rgba(1, 8, 12, 0.88);
  backdrop-filter: blur(8px);
}
#gameOverBox {
  width: min(480px, 100%);
  padding: 34px;
  text-align: center;
  color: var(--ak-text);
  background: #12242c;
  border: 1px solid rgba(255, 210, 74, 0.5);
  border-radius: 18px;
}
#gameOverMessage { line-height: 1.55; }
#akResultActions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.ak-effect {
  position: absolute;
  z-index: 1001;
  pointer-events: none;
}
.ak-pickup-feedback { font-size: 20px; font-weight: 900; transition: transform 0.8s ease, opacity 0.8s ease; }

@media (max-width: 920px) {
  .ak-game-topbar { grid-template-columns: 1fr auto; }
  .ak-room-meta { display: none; }
  .ak-stage-banner { grid-template-columns: 1fr 1.6fr; }
  .ak-stage-cell.metrics { grid-column: 1 / -1; min-height: 60px; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; }
  .ak-play-layout { grid-template-columns: 1fr; }
  .ak-side-panel { display: grid; grid-template-columns: 1fr 220px; gap: 16px; }
  .ak-side-actions { align-content: start; }
}

@media (max-width: 640px) {
  body.alkkagi-game-page { padding: 0 8px 28px; }
  .ak-game-topbar { position: relative; grid-template-columns: 1fr; border-radius: 0 0 12px 12px; }
  .ak-top-actions, .ak-user-summary { justify-content: center; flex-wrap: wrap; }
  .ak-game-shell { margin-top: 12px; }
  .ak-stage-banner { grid-template-columns: 1fr; }
  .ak-stage-cell { min-height: 70px; padding: 12px 14px; }
  .ak-stage-cell.metrics { grid-column: auto; }
  .ak-player-strip { grid-template-columns: 1fr 34px 1fr; gap: 5px; }
  .ak-player-card { min-height: 64px; padding: 9px 9px 9px 40px; font-size: 13px; }
  .ak-player-card::before { left: 9px; width: 23px; height: 23px; }
  .ak-board-panel { padding: 5px; border-radius: 11px; }
  .ak-side-panel { display: block; padding: 14px; }
  .game-status { min-height: 52px; font-size: 16px; }
  .item-legend { grid-template-columns: 1fr; }
}
