@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700;800&family=Geist+Mono:wght@400;500;600;700&family=Saira:wght@500;600&display=swap");

:root {
  --bg: #0a0a0a;
  --panel: #111111;
  --panel-2: #151515;
  --border: #262626;
  --border-hover: #333333;
  --muted: #a1a1aa;
  --text: #f5f5f5;
  --accent: #0070f3;
  --good: #22c55e;
  --bad: #ef4444;
  --board-shell: #0f0f0f;
  --board-border: #262626;
  --board-handle: #333333;
  --board-light: #DFE3E6;
  --board-dark: #90A1AB;
  --board-size: 60%;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: "Geist", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  user-select: none;
}

.navbar {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1rem;
  text-align: center;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.navbar .title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: "Saira", "Geist", system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  letter-spacing: 0.3px;
  margin: 0;
}

.title-icon svg {
  display: block;
  width: 20px;
  height: 20px;
}

.app {
  width: min(1100px, 95vw);
  margin: 0 auto;
  flex: 1;
}

.site-footer {
  margin-top: auto;
  padding: 16px 0;
  text-align: center;
  font-size: 0.8rem;
  color: #6b7280;
}

.header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 12px;
  padding-top: 2rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.controls-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  font-family: "Geist", system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

button,
select,
.toggle {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
  font-family: "Geist", system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
}

.material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a1a1aa' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 34px;
}

button:hover {
  border-color: var(--border-hover);
}

.row {
  display: grid;
  grid-template-columns: var(--board-size) 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 960px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .navbar {
    justify-content: flex-start;
  }

  .navbar .title {
    text-align: left;
    font-size: 0.9rem;
  }

  .app {
    width: calc(100% - 24px);
  }

  .pgn-toggle {
    display: none;
  }

  .current-move-card {
    display: none;
  }

  .panel {
    padding: 8px;
  }

  .resize-handle {
    display: none;
  }

  .controls-toggle {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-top: 0;
    padding-top: 0;
  }

  .controls-toggle {
    display: inline-flex;
  }

  .controls {
    display: none;
    width: 100%;
  }

  .row {
    gap: 12px;
  }

  .controls.open {
    display: flex;
  }

  .row {
    grid-template-columns: 1fr;
  }
}

.board-wrap {
  border-radius: 16px;
  padding: 12px;
  position: relative;
  width: 100%;
}

@media (max-width: 960px) {
  .board-wrap {
    padding: 0;
  }
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 14px;
  overflow: hidden;
}

.resize-handle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  background: transparent;
  border-radius: 2px;
  opacity: 0.9;
  touch-action: none;
  z-index: 6;
}

.resize-handle::before,
.resize-handle::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  border-right: 2px solid var(--board-handle);
  border-bottom: 2px solid var(--board-handle);
}

.resize-handle::before {
  width: 8px;
  height: 8px;
}

.resize-handle::after {
  width: 6px;
  height: 6px;
}

.board-wrap.resizing {
  user-select: none;
}

.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.sq.light {
  background: var(--board-light);
}

.sq.dark {
  background: var(--board-dark);
}

.sq.selected {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.sq svg {
  width: 90%;
  height: 90%;
  display: block;
  pointer-events: none;
}

.sq.coord-on::after {
  content: attr(data-ax);
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 12px;
  color: #0009;
  font-weight: 700;
}

/* Flash overlay layer */
.flash-layer {
  position: absolute;
  inset: 12px;
  pointer-events: none;
  z-index: 5;
  border-radius: 14px;
  overflow: hidden;
}

@media (max-width: 960px) {
  .flash-layer {
    inset: 0;
    border-radius: 0;
  }
}

.flash-square {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
}

/* Drag visuals */
.drag-ghost {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.drag-ghost svg {
  width: 90%;
  height: 90%;
  display: block;
}

.sq.drag-hide > * {
  opacity: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

@media (max-width: 960px) {
  .stats {
    margin-top: 0;
  }
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.card .h {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.card .v {
  font-size: 22px;
  font-weight: 800;
}

.foot {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

/* Big move label in the centre (fades away) */
.target-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.target-overlay.hidden {
  opacity: 0;
}

.kbd {
  font-family: "Geist Mono", ui-monospace, monospace;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
}

.help {
  font-size: 14px;
  color: var(--muted);
}

/* PGN tools */
.pgn-tools {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.pgn-tools textarea {
  width: 100%;
  min-height: 90px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-family: ui-monospace, monospace;
}

.pgn-tools .col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.pgn-tools .btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none;
}
