/* =========================================================================
   GAME WORKSPACE (LEFT: BOARD + CLOCKS + REPLAY / RIGHT: 330px SIDEBAR)
   ========================================================================= */
.workspace {
  max-width: 1000px;
  margin: 0 auto;
  padding: 14px 12px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* Reconnect Countdown Banner */
.reconnect-banner {
  width: calc(var(--board-size) + 34px);
  max-width: 96vw;
  padding: 8px 12px;
  border-radius: 8px;
  background: #fdecec;
  border: 1.5px solid var(--vermilion);
  color: #7d1111;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

/* Player Strip with Clock */
.player-strip {
  width: calc(var(--board-size) + 34px);
  max-width: 96vw;
  padding: 7px 12px;
  border-radius: 9px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 3px 10px rgba(56, 39, 18, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.player-strip.active-turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 1.5px rgba(140, 101, 37, 0.35), 0 4px 12px rgba(90, 62, 22, 0.14);
}
.player-strip.opponent {
  border-color: rgba(166, 28, 28, 0.24);
}
.player-strip.opponent.active-turn {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 1.5px rgba(166, 28, 28, 0.28);
}

.player-ident {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.side-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
  background: rgba(215, 166, 86, 0.26);
  color: #5a3a08;
  white-space: nowrap;
}
.player-strip.opponent .side-badge {
  background: rgba(166, 28, 28, 0.12);
  color: #8b1717;
}
.player-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clock-box {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel-bg-soft);
  border: 1px solid rgba(133, 102, 60, 0.3);
  color: var(--text-main);
  white-space: nowrap;
  flex-shrink: 0;
}
.clock-box.byoyomi {
  border-color: #b47b1e;
  background: #fdf3dc;
  color: #6b4308;
}
.clock-box.urgent {
  border-color: var(--vermilion);
  background: #fbd9d9;
  color: #841212;
  animation: pulseClock 0.9s infinite;
}
@keyframes pulseClock {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* =========================================================================
   WOODEN KOMADAI (HAND TRAYS)
   ========================================================================= */
.hand-panel {
  width: calc(var(--board-size) + 34px);
  max-width: 96vw;
  height: 54px;
  padding: 5px 10px;
  border-radius: 9px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='60'%3E%3Cfilter id='kd'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.018 0.35' numOctaves='3' seed='4'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.35 0 0 0 0 0.2 0 0 0 0 0.06 0 0 0 0.14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23kd)'/%3E%3C/svg%3E"),
    linear-gradient(175deg, #e7c68b 0%, #d4a65a 100%);
  border: 1.5px solid #8a5c28;
  box-shadow: 0 4px 12px rgba(48, 30, 10, 0.18), inset 0 1px 0 rgba(255, 245, 220, 0.48);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.hand-panel.opponent {
  border-color: #7e4b2c;
}
.hand-label {
  width: 58px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 800;
  color: #311f0a;
  text-align: center;
  border-right: 1px solid rgba(72, 44, 15, 0.28);
  padding-right: 6px;
  line-height: 1.25;
}
.hand-label > div:last-child { color: rgba(49, 31, 10, 0.78) !important; }
.hand-panel.opponent .hand-label { color: #541c1c; }
.hand-panel.opponent .hand-label > div:last-child { color: rgba(84, 28, 28, 0.78) !important; }

.hand-slots {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  height: 42px;
  align-items: stretch;
}
.hand-slot {
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  background: rgba(255, 249, 236, 0.32);
  border: 1px solid rgba(90, 56, 18, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 2px;
  opacity: 0.45;
  cursor: default;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  overflow: hidden;
}
.hand-slot.has-piece {
  opacity: 1;
  background: linear-gradient(175deg, #faeccb, #e7c07c);
  border-color: rgba(110, 70, 20, 0.55);
  box-shadow: 0 1px 3px rgba(45, 26, 7, 0.22), inset 0 1px 0 rgba(255, 250, 236, 0.7);
}
.hand-slot.playable { cursor: pointer; }
.hand-slot.playable:hover {
  background: linear-gradient(175deg, #fff5dc, #f1cf92);
  border-color: #6a4712;
}
.hand-slot.selected {
  background: linear-gradient(175deg, #fff8e2, #f3d28f);
  border-color: #6a4712;
  box-shadow: inset 0 0 0 1.5px #a65c0a;
}
.hand-slot-name {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 800;
  color: #1f1409;
  line-height: 1;
}
.hand-panel.opponent .hand-slot-name { color: #471414; }
.hand-slot-cnt {
  font-size: 10px;
  font-weight: 700;
  color: #463016;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.opp-fog-summary {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: #2f2213;
  background: rgba(255, 249, 236, 0.35);
  border-radius: 6px;
  height: 36px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opp-fog-count {
  font-weight: 800;
  color: var(--vermilion);
  margin: 0 3px;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   HON-KAYA LUXURY SHOGI BOARD & STARS
   ========================================================================= */
.board-frame {
  padding: 11px 11px 13px 13px;
  border-radius: 10px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='fr'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.22 0.015' numOctaves='3' seed='3'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.12 0 0 0 0 0.06 0 0 0 0 0.02 0 0 0 0.28 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23fr)'/%3E%3C/svg%3E"),
    linear-gradient(155deg, #5e3916 0%, #3d220a 55%, #2a1505 100%);
  border: 2px solid #754a1f;
  box-shadow:
    0 20px 38px -8px rgba(34, 21, 7, 0.48),
    0 6px 14px rgba(34, 21, 7, 0.28),
    inset 0 1px 0 rgba(255, 224, 168, 0.32),
    inset 0 -2px 4px rgba(15, 8, 2, 0.65);
  width: calc(var(--board-size) + 34px);
  max-width: 96vw;
}

.coord-top {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: var(--board-size);
  max-width: 100%;
  margin-bottom: 4px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 700;
  color: #ebd0a0;
  user-select: none;
}
.board-row-wrap {
  display: flex;
  align-items: stretch;
}
.coord-right {
  width: 16px;
  flex-shrink: 0;
  display: grid;
  grid-template-rows: repeat(9, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 700;
  color: #ebd0a0;
  padding-left: 4px;
  user-select: none;
}

.board-stage {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
}

/* 4 Stars (Hoshi) on 3-3, 3-6, 6-3, 6-6 intersections */
.board-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.board-stars span {
  position: absolute;
  width: 5.5px;
  height: 5.5px;
  border-radius: 50%;
  background: #231406;
  transform: translate(-50%, -50%);
}
.board-stars span:nth-child(1) { left: 33.3333%; top: 33.3333%; }
.board-stars span:nth-child(2) { left: 66.6667%; top: 33.3333%; }
.board-stars span:nth-child(3) { left: 33.3333%; top: 66.6667%; }
.board-stars span:nth-child(4) { left: 66.6667%; top: 66.6667%; }

.shogi-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='k'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.24 0.013' numOctaves='4' seed='7'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.36 0 0 0 0 0.19 0 0 0 0 0.04 0 0 0 0.17 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23k)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(90deg, rgba(128, 76, 18, 0.045) 0px, rgba(128, 76, 18, 0.045) 3px, transparent 3px, transparent 14px),
    linear-gradient(162deg, #eccb8a 0%, #dda954 48%, #c98f3a 100%);
  border: 2px solid #261606;
  box-shadow: inset 0 0 18px rgba(74, 42, 10, 0.24);
  overflow: hidden;
}

.sq {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-right: 1px solid rgba(36, 20, 6, 0.74);
  border-bottom: 1px solid rgba(36, 20, 6, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}
.sq:nth-child(9n) { border-right: none; }
.sq:nth-child(n+73) { border-bottom: none; }

.sq.visible {
  background: radial-gradient(circle at center, rgba(255, 250, 232, 0.28), rgba(255, 240, 198, 0.03));
}

/* Sumi-e Mist / Fog of War */
.sq.fogged::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 28% 28%, rgba(244, 237, 224, 0.14), transparent 64%),
    radial-gradient(circle at 75% 78%, rgba(164, 155, 142, 0.16), transparent 62%),
    rgba(39, 43, 49, 0.86);
  z-index: 4;
  pointer-events: none;
}
.sq.fogged:hover::before {
  background:
    radial-gradient(circle at 50% 50%, rgba(232, 189, 114, 0.22), transparent 68%),
    rgba(47, 50, 56, 0.81);
}

.sq.selected {
  background: rgba(217, 119, 6, 0.38) !important;
  box-shadow: inset 0 0 0 2px #92400e;
}
.sq.last-own {
  box-shadow: inset 0 0 0 2px rgba(180, 83, 9, 0.65);
}

.target-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(37, 87, 119, 0.84);
  border: 2px solid #f5efe2;
  box-shadow: 0 1px 4px rgba(18, 42, 58, 0.5);
  z-index: 6;
  pointer-events: none;
}
.sq.capture-visible .target-dot {
  width: 84%;
  height: 84%;
  border-radius: 5px;
  background: rgba(166, 28, 28, 0.18);
  border: 2px solid var(--vermilion);
  box-shadow: none;
}
.sq.drop-target .target-dot {
  width: 26%;
  height: 26%;
  background: rgba(140, 101, 37, 0.82);
  border: 1.5px solid #fbf6ec;
  box-shadow: none;
}
.sq.drop-target.fogged .target-dot {
  background: rgba(235, 202, 139, 0.65);
  border-color: rgba(252, 248, 240, 0.72);
}

@keyframes fxGold {
  0% { background: rgba(217, 119, 6, 0.62); }
  100% { background: transparent; }
}
@keyframes fxRed {
  0% { background: rgba(185, 28, 28, 0.64); }
  100% { background: transparent; }
}
.fx-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}
.fx-collision { animation: fxGold 0.85s ease-out forwards; box-shadow: inset 0 0 0 2px #d97706; }
.fx-trap { animation: fxRed 0.9s ease-out forwards; box-shadow: inset 0 0 0 2px #b91c1c; }

/* =========================================================================
   MIKURAJIMA TSUGE SHOGI PIECES (REAL WOOD GRAIN & BEVEL DEPTH)
   ========================================================================= */
.koma-wrap {
  width: 87%;
  height: 89%;
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  filter:
    drop-shadow(0 2.5px 2px rgba(32, 17, 4, 0.52))
    drop-shadow(0 1px 0.5px rgba(24, 12, 2, 0.42));
  pointer-events: none;
}
.koma-wrap.opponent {
  transform: rotate(180deg);
}
.koma {
  width: 100%;
  height: 100%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='t'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.34 0.024' numOctaves='3' seed='12'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.45 0 0 0 0 0.25 0 0 0 0 0.05 0 0 0 0.14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23t)'/%3E%3C/svg%3E"),
    linear-gradient(to bottom, rgba(255, 250, 232, 0.46) 0%, transparent 15%, transparent 86%, rgba(92, 52, 12, 0.34) 100%),
    linear-gradient(to right, rgba(102, 58, 14, 0.2) 0%, transparent 15%, transparent 85%, rgba(102, 58, 14, 0.2) 100%),
    linear-gradient(168deg, #faebc3 0%, #ebcd8d 52%, #d3a65c 100%);
  clip-path: polygon(50% 2%, 90% 18%, 99% 98%, 1% 98%, 10% 18%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 10%;
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: clamp(13px, 3.2vw, 21px);
  color: #181008;
  text-shadow: 0 1px 0 rgba(255, 248, 224, 0.45);
  line-height: 1;
  overflow: hidden;
}
.koma.two-char {
  font-size: clamp(9px, 2vw, 13px);
  writing-mode: vertical-rl;
  padding-top: 6%;
}
.koma.promoted { color: var(--vermilion); }
.koma.king {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='tk'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.34 0.024' numOctaves='3' seed='21'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.45 0 0 0 0 0.25 0 0 0 0 0.05 0 0 0 0.13 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23tk)'/%3E%3C/svg%3E"),
    linear-gradient(to bottom, rgba(255, 252, 238, 0.55) 0%, transparent 16%, transparent 85%, rgba(92, 52, 12, 0.34) 100%),
    linear-gradient(to right, rgba(102, 58, 14, 0.18) 0%, transparent 15%, transparent 85%, rgba(102, 58, 14, 0.18) 100%),
    linear-gradient(168deg, #fff4d8 0%, #f1d9a2 52%, #dab068 100%);
}

/* =========================================================================
   POST-GAME REPLAY BAR
   ========================================================================= */
.replay-bar {
  width: calc(var(--board-size) + 34px);
  max-width: 96vw;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.replay-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.replay-slider {
  flex: 1;
  min-width: 110px;
  accent-color: var(--gold);
}
.replay-summary {
  font-size: 11.5px;
  color: var(--text-sub);
}

/* =========================================================================
   RIGHT SIDEBAR (330px)
   ========================================================================= */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.side-card {
  padding: 14px;
  min-width: 0;
}
.turn-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}
.turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--gold-bright);
}
.turn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(140, 101, 37, 0.55);
  flex-shrink: 0;
}
.turn-dot.opp {
  background: var(--vermilion);
  box-shadow: 0 0 6px rgba(166, 28, 28, 0.5);
  animation: pulseThinking 1.4s ease-in-out infinite;
}
@keyframes pulseThinking {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.ply-text {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.vis-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.game-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.side-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.side-tab {
  flex: 1;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-bg-soft);
  border: 1px solid rgba(133, 102, 60, 0.25);
  color: var(--text-muted);
  position: relative;
}
.side-tab.active {
  border-color: var(--gold);
  background: rgba(235, 202, 139, 0.34);
  color: #543507;
}
.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--vermilion);
  margin-left: 5px;
}

.log-box {
  height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.log-item {
  font-size: 11.5px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-bg-soft);
  border-left: 3px solid #9c8f7e;
  color: var(--text-sub);
  line-height: 1.45;
}
.log-item.own { border-left-color: var(--gold); color: var(--text-main); }
.log-item.collision {
  border-left-color: #b47b1e;
  background: #fdf3dc;
  color: #6b4308;
}
.log-item.trap {
  border-left-color: var(--vermilion);
  background: #fdecec;
  color: #7d1111;
}
.log-item.system {
  border-left-color: var(--sky);
  background: #edf5fa;
  color: #193e57;
}
.log-ply {
  font-size: 10px;
  color: var(--text-muted);
  margin-right: 5px;
  font-variant-numeric: tabular-nums;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.quick-chip {
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fffdf8;
  border: 1px solid rgba(133, 102, 60, 0.3);
  color: var(--text-sub);
}
.quick-chip:hover { border-color: var(--gold); color: var(--gold-bright); }

.promo-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.promo-btn {
  padding: 14px 10px;
  border-radius: 9px;
  background: var(--panel-bg-soft);
  border: 1.5px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.promo-btn:hover {
  border-color: var(--gold);
  background: rgba(235, 202, 139, 0.3);
}
.promo-preview {
  width: 48px;
  height: 50px;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 10px 8px 24px;
    gap: 12px;
  }
  .side-panel {
    width: 100%;
    max-width: 520px;
  }
}
@media (max-width: 480px) {
  :root {
    --board-size: min(88vw, 352px);
  }
  .board-frame {
    padding: 8px 8px 10px 9px;
  }
}
