/* static/css/style.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --eval-pos: #e63946;
  --eval-neg: #457b9d;
  --eval-zero: #888;
  --bg: #1a1a2e;
  --text: #eee;
  --control-bg: #16213e;
  --btn-bg: #0f3460;
  --btn-active: #e94560;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic Pro", "Meiryo", sans-serif;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  margin: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  gap: 4px;
  overflow-x: clip;
  overflow-y: visible;
}

#hands-top,
#hands-bottom {
  flex-shrink: 0;
  height: 44px;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0;
  overflow: hidden;
}

#board-container {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  display: grid;
  place-items: center;
  overflow-x: clip;
  overflow-y: visible;
}

#board-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  max-height: 100%;
  touch-action: none;
  cursor: pointer;
}

#controls {
  flex-shrink: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  background: var(--control-bg);
  border-radius: 0;
}

#controls button {
  padding: 0 10px;
  font-size: 13px;
}

#game-controls {
  flex-shrink: 0;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.04);
}

#game-status {
  font-size: 12px;
  color: #cfd8e3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#flash-banner {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
  color: #ff2a2a;
  font-weight: 900;
  font-size: clamp(40px, 12vw, 84px);
  letter-spacing: 0.08em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  word-break: keep-all;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
}

#flash-banner.show {
  animation: flashBanner 1s ease-out forwards;
}

@keyframes flashBanner {
  0% { opacity: 0; transform: translate(-50%, -56%) scale(0.9); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -44%) scale(1.04); }
}

button {
  background: var(--btn-bg);
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 0 14px;
  height: 30px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active { background: var(--btn-active); }
#btn-winout-mode,
#btn-winout-mode:disabled {
  background: #b71c1c !important;
  color: #fff !important;
  opacity: 1;
}
#btn-winout-mode:active { background: #8b1313 !important; }

#eval-display {
  font-size: 16px;
  font-weight: bold;
  min-width: 64px;
  text-align: center;
  flex-shrink: 0;
}
.eval-pos { color: var(--eval-pos); }
.eval-neg { color: var(--eval-neg); }
.eval-zero { color: var(--eval-zero); }

#progress-bar {
  height: 3px;
  background: var(--btn-active);
  width: 0%;
  transition: width 0.3s;
  border-radius: 2px;
  flex: 1;
  min-width: 0;
  align-self: center;
}

#graph-canvas {
  flex-shrink: 0;
  width: 100%;
  height: 64px;
  display: block;
  touch-action: none;
  border-radius: 0;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}
#graph-canvas.visible { visibility: visible; opacity: 1; }

#pv-display {
  flex-shrink: 0;
  min-height: 54px;
  font-size: 16px;
  color: #e8edf8;
  padding: 4px 8px 6px;
  line-height: 1.25;
  overflow: hidden;
  visibility: hidden;
}
#pv-display.visible { visibility: visible; }
.pv-best {
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.pv-line {
  margin-top: 2px;
  font-size: 15px;
  color: #d7dfef;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

#promotion-dialog {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--control-bg);
  border: 2px solid var(--btn-active);
  border-radius: 12px;
  padding: 20px;
  z-index: 100;
  text-align: center;
  min-width: 200px;
}
#promotion-dialog.visible { display: block; }
#promotion-dialog p { margin-bottom: 12px; font-size: 16px; }
#promotion-dialog button { margin: 0 6px; font-size: 16px; padding: 0 20px; height: 40px; }

.hand-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f5deb3;
  color: #000;
  border: 1px solid #6f4f2a;
  border-radius: 4px;
  font-size: 24px;
  line-height: 1;
  padding: 0 8px;
  min-width: 34px;
  height: 34px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}
.hand-piece:active { background: #ffe066; }
.hand-piece-count { font-size: 12px; margin-left: 2px; color: #555; }
.hand-piece.selected {
  transform: translateY(-3px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  background: #ffe066;
}

.hand-piece-image {
  position: relative;
  color: transparent;
  background-color: transparent;
  border: none;
  min-width: 30px;
  width: 30px;
  height: 34px;
  padding: 0;
}

.hand-piece-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url('/images/pieces.png');
  background-repeat: no-repeat;
  background-size: calc(8 * 100%) calc(4 * 100%);
  background-position:
    calc(var(--hand-piece-col, 0) * (100% / 7)) calc(var(--hand-piece-row, 0) * (100% / 3));
}

.hand-piece-image .hand-piece-count {
  position: absolute;
  right: -1px;
  bottom: -3px;
  margin-left: 0;
  padding: 0 2px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  line-height: 1.2;
}
