:root {
  --bg: #ffffff;
  --panel: #fbfcfa;
  --ink: #1f2428;
  --muted: #68716f;
  --line: #cbd5d1;
  --board: #f2c25d;
  --board-line: #000000;
  --board-dot: rgba(76, 86, 32, 0.6);
  --board-highlight: #d8cd4d;
  --board-last: #e6d772;
  --accent: #8d4f1f;
  --move: #1f7772;
  --drop: #317548;
  --capture: #b63e44;
  --shadow: 0 18px 45px rgba(24, 34, 36, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", system-ui, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  overflow: hidden;
}

button {
  font: inherit;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.site-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px 14px;
  flex-wrap: wrap;
  padding: 10px 16px 0;
  background: transparent;
}

.site-header h1 {
  margin: 0;
  font-size: 1.22rem;
  line-height: 1.5;
  letter-spacing: 0;
}

.tagline {
  color: var(--muted);
  font-size: 0.86rem;
}

.hlinks {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.86rem;
  white-space: nowrap;
}

.hlinks a,
.navbtn {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.hlinks a:hover,
.navbtn:hover {
  text-decoration: underline;
}

.navbtn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}

.icon-button,
.face-button {
  border: 1px solid rgba(58, 75, 72, 0.24);
  background: #ffffff;
  color: var(--ink);
  border-radius: 7px;
  cursor: pointer;
  min-height: 32px;
}

.icon-button {
  width: 34px;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
}

.icon-button:hover,
.face-button:hover {
  background: #eef3ef;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 620px) minmax(294px, 372px);
  gap: 18px;
  align-items: stretch;
  justify-content: center;
  padding: 12px 16px 14px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.board-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 0;
}

.hand {
  min-height: 58px;
  border: 1px solid rgba(58, 75, 72, 0.18);
  background: #fbfcfa;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset;
}

.hand.active {
  border-color: rgba(161, 95, 34, 0.72);
  box-shadow: 0 0 0 3px rgba(161, 95, 34, 0.12);
}

.hand-label {
  width: 58px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hand-pieces {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.hand-chip {
  width: 48px;
  height: 42px;
  border: 1px solid rgba(72, 52, 20, 0.18);
  border-radius: 7px;
  background: #fffdf8;
  cursor: pointer;
  position: relative;
  display: grid;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.68) inset,
    0 2px 5px rgba(58, 37, 12, 0.08);
}

.hand-chip.gote {
  background: #fffdf8;
}

.hand-chip.disabled {
  opacity: 0.28;
  cursor: default;
}

.hand-chip.selected {
  outline: 3px solid rgba(47, 123, 67, 0.32);
}

.hand-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(35, 24, 8, 0.18));
}

.hand-count {
  position: absolute;
  z-index: 2;
  right: -7px;
  bottom: -8px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fffdf8;
  color: var(--ink);
  border: 1px solid rgba(92, 72, 34, 0.28);
  font-size: 0.74rem;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
}

.board {
  width: min(100%, calc((100vh - 176px) * 0.8));
  max-width: 500px;
  min-width: 300px;
  aspect-ratio: 4 / 5;
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2px;
  padding: 2px;
  background: var(--board-line);
  border: 2px solid var(--board-line);
  border-radius: 0;
  box-shadow: 0 14px 32px rgba(24, 24, 18, 0.2);
}

.move-preview {
  position: absolute;
  z-index: 5;
  inset: 4px;
  color: rgba(141, 79, 31, 0.92);
  pointer-events: none;
  overflow: visible;
}

.move-preview-arrow {
  opacity: 0.9;
  filter: drop-shadow(0 2px 2px rgba(43, 29, 8, 0.3));
}

.move-preview-line {
  stroke: currentColor;
  stroke-linecap: round;
}

.move-preview-head {
  fill: currentColor;
}

.move-preview-drop {
  fill: rgba(141, 79, 31, 0.12);
  stroke: currentColor;
  stroke-width: 7;
  filter: drop-shadow(0 2px 2px rgba(43, 29, 8, 0.25));
}

@media (max-height: 760px) and (min-width: 901px) {
  .board {
    width: min(100%, calc((100vh - 224px) * 0.8));
  }
}

.cell {
  border: 0;
  padding: 0;
  border-radius: 0;
  background: var(--board);
  position: relative;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
}

.cell:hover {
  background: #f5c967;
}

.cell.selected {
  background: var(--board-highlight);
}

.cell.target::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 36%;
  border-radius: 999px;
  background: var(--board-dot);
  pointer-events: none;
}

.cell.drop-target::after {
  background: var(--board-dot);
}

.cell.capture-target::after {
  inset: 14%;
  border: 5px solid var(--board-dot);
  background: transparent;
}

.cell.last {
  background: var(--board-last);
}

.cell.last.selected {
  background: var(--board-highlight);
}

.edge-label {
  position: absolute;
  z-index: 3;
  color: #000000;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.file-label {
  left: 7px;
  top: 6px;
}

.rank-label {
  right: 7px;
  top: 6px;
}

.piece {
  position: absolute;
  z-index: 2;
  inset: 4% 9%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.piece.draggable-piece {
  cursor: grab;
  pointer-events: auto;
}

.piece.draggable-piece:active {
  cursor: grabbing;
}

.piece-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 5px 5px rgba(43, 29, 8, 0.22));
}

.drag-ghost {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 6px rgba(43, 29, 8, 0.28));
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid rgba(117, 91, 43, 0.18);
  border-radius: 8px;
  box-shadow: 0 8px 26px rgba(44, 38, 23, 0.08);
  overflow: hidden;
}

.status {
  padding: 9px 14px;
  border-left: 5px solid var(--accent);
  background: #fff8e7;
}

.status-title {
  font-weight: 800;
  font-size: 0.98rem;
}

.status-subtitle {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.face-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-top: 1px solid rgba(117, 91, 43, 0.13);
  background: #fbf7ed;
}

.face-row[hidden] {
  display: none;
}

.face-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.face-button {
  min-width: 54px;
  padding: 5px 9px;
  font-weight: 800;
}

.face-button.active {
  background: var(--drop);
  color: white;
  border-color: var(--drop);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 14px;
  border-top: 1px solid rgba(117, 91, 43, 0.13);
}

.spacer {
  flex: 1;
}

.section-title {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  padding: 6px 14px 2px;
  border-top: 1px solid rgba(117, 91, 43, 0.13);
}

.history {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 48px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 14px 6px;
}

.history button {
  flex: 0 1 auto;
  max-width: 100%;
  border: 1px solid transparent;
  background: #f4efe3;
  border-radius: 7px;
  padding: 4px 7px;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.79rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history button.current {
  background: var(--accent);
  color: white;
}

.move-list {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid rgba(117, 91, 43, 0.13);
  padding: 4px 0 10px;
}

.move-group {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 7px 14px 3px;
}

.move-row {
  width: 100%;
  border: 0;
  background: transparent;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
}

.move-row:hover {
  background: #f8efd9;
}

.move-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  justify-self: end;
  max-width: 150px;
}

.tag {
  border-radius: 999px;
  padding: 2px 7px;
  color: white;
  font-size: 0.68rem;
  font-weight: 800;
}

.tag.move {
  background: var(--move);
}

.tag.drop {
  background: var(--drop);
}

.tag.capture {
  background: var(--capture);
}

.tag.flip {
  background: var(--accent);
}

.empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 10px 14px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 26, 29, 0.48);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(620px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: #fffdf8;
  border-radius: 8px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.3rem;
}

.modal-card h3 {
  margin: 18px 0 6px;
  font-size: 0.98rem;
}

.modal-card p,
.modal-card li {
  color: #343840;
  font-size: 0.94rem;
}

.modal-card ul {
  margin: 7px 0 0;
  padding-left: 20px;
}

.credit {
  border-top: 1px solid rgba(117, 91, 43, 0.18);
  margin-top: 18px;
  padding-top: 12px;
  font-size: 0.82rem;
}

.modal-close {
  margin-left: auto;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app {
    display: block;
    height: auto;
  }

  .site-header {
    align-items: flex-start;
  }

  .tagline {
    display: none;
  }

  .hlinks {
    margin-left: 0;
    flex-wrap: wrap;
    gap: 10px 14px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    height: auto;
    overflow: visible;
  }

  .board {
    width: min(100%, 430px);
    min-width: 0;
  }

  .side-panel {
    max-height: 620px;
  }
}

@media (max-width: 520px) {
  .site-header {
    gap: 10px;
    padding: 11px 12px;
  }

  .layout {
    padding: 10px;
    gap: 12px;
  }

  .hand {
    min-height: 58px;
    padding: 7px;
  }

  .hand-label {
    width: 46px;
    font-size: 0.66rem;
  }

  .hand-chip {
    width: 44px;
    height: 36px;
  }
}
