:root {
  --header-control-height: 36px;
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #20242d;
  --muted: #6b7280;
  --line: #dfe3ea;
  --accent: #0f8f7b;
  --accent-dark: #08705f;
  --danger: #d55244;
  --gold: #e2a52d;
  --light-square: #ede7d0;
  --dark-square: #6f9a71;
  --focus: 0 0 0 3px rgba(15, 143, 123, 0.25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

input,
button,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

a:focus-visible,
input:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

button,
a,
.square,
.board-grid,
.icon-action,
.coffee-link,
.state-toggle,
.piece-button,
.toggle-button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.app-shell {
  position: fixed;
  inset-inline: 0;
  top: var(--app-viewport-top, 0px);
  width: min(780px, 100%);
  height: var(--app-viewport-height, 100dvh);
  margin: 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 4px 2px;
}

.title-block {
  min-width: 0;
  display: grid;
  align-content: start;
}

h1,
h2,
p {
  margin: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(430px, 100%);
  margin-bottom: 10px;
  line-height: 1;
  white-space: nowrap;
}

.brand-ink {
  fill: #15171a;
}

.brand-paper {
  fill: #f8fafc;
}

.brand-accent {
  fill: var(--accent);
}

.brand-accent-stroke {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 10;
}

.brand-mark {
  flex: 0 0 auto;
  width: calc(var(--header-control-height) * 234 / 154);
  height: var(--header-control-height);
  overflow: visible;
}

.brand-name {
  fill: #15171a;
  color: #15171a;
  min-width: 0;
  font-size: clamp(1.35rem, 3.2vw, 1.65rem);
  font-weight: 850;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 7vw, 2.15rem);
  line-height: 1;
  letter-spacing: 0;
}

.tagline {
  margin-top: 0;
  color: var(--muted);
  font-size: clamp(0.86rem, 3.8vw, 1rem);
  font-weight: 700;
  line-height: 1.2;
}

.tagline-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.panel {
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 12px 34px rgba(32, 36, 45, 0.06);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-heading > div:first-child { min-width: 0; }

.source-actions {
  display: grid;
  grid-template-columns: 207px;
  grid-template-rows: repeat(2, 44px);
  align-items: center;
  gap: 8px;
  width: auto;
  justify-self: end;
}

.board-source-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.coffee-link {
  display: block;
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  width: 207px;
  height: 44px;
  line-height: 1;
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
}

.coffee-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.coffee-link:active {
  transform: translateY(1px);
}

.icon-action {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.contact-action {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
  justify-self: end;
  width: max-content;
  height: var(--header-control-height);
  padding-inline: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent-dark);
  background: #ffffff;
  font-weight: 850;
  font-size: 0.82rem;
  cursor: pointer;
}

.contact-action:active {
  transform: translateY(1px);
}

.icon-action svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.camera-action {
  display: none;
}

.native-mobile .camera-action {
  display: grid;
}

.native-ios .paste-action {
  display: none;
}

.native-android .paste-action {
  display: none;
}

.paste-action {
  display: grid;
}

.native-mobile .paste-action,
.native-mobile .desktop-copy { display: none; }
.native-mobile .mobile-copy { display: grid; }

.info-action {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transform: translateY(-1px);
}

.info-action span {
  display: block;
  width: auto;
  height: auto;
  border: 0;
  font-size: 17px;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  transform: translate(-0.5px, -0.5px);
}

.icon-action:active,
.info-action:active,
.state-toggle:active {
  transform: translateY(1px);
}

body.has-modal {
  overflow: hidden;
}

.info-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(33, 38, 49, 0.48);
}

.info-overlay[hidden] {
  display: none;
}

.info-card {
  width: min(100%, 520px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(20, 25, 35, 0.18);
}

.info-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.info-card-header h2 {
  font-size: 1.05rem;
}

.info-close-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
  background: #f4f6f9;
  cursor: pointer;
}

.info-close-button svg,
.info-thumbnail svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.contact-form {
  display: grid;
  gap: 8px;
}

.contact-form label {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.contact-form label span,
.contact-note {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.contact-form textarea,
.contact-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
}

.contact-form textarea {
  min-height: 118px;
  resize: vertical;
}

.contact-trap {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.contact-note,
.contact-form-status {
  margin: 2px 0;
}

.contact-form-status {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 650;
}

.contact-form-status.is-success {
  color: var(--accent-dark);
}

.contact-send-button {
  justify-self: start;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 850;
  cursor: pointer;
}

.contact-send-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.info-steps {
  display: grid;
  gap: 14px;
}

.info-step {
  display: grid;
  grid-template-columns: 24px 86px minmax(0, 1fr);
  column-gap: 18px;
  row-gap: 6px;
  align-items: center;
}

.info-step-number {
  display: grid;
  place-items: center;
  align-self: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
}

.info-step p {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.38;
}

.info-thumbnails {
  display: flex;
  gap: 6px;
  align-items: start;
  min-width: 0;
}

.info-thumbnail {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
}

.info-piece-thumbnail {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
}

.info-piece-thumbnail img {
  width: 31px;
  height: 31px;
}

.info-remove-thumbnail {
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line);
}

.info-camera-thumbnail,
.mobile-copy {
  display: none;
}

.info-toggle-thumbnails {
  display: grid;
  gap: 5px;
  justify-items: start;
  justify-self: start;
}

.info-state-chip {
  display: grid;
  place-items: center;
  width: max-content;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 850;
  white-space: nowrap;
}

.info-orientation-chip {
  background: rgba(226, 165, 45, 0.14);
  color: #825600;
}

.info-turn-chip {
  background: rgba(15, 143, 123, 0.12);
  color: var(--accent-dark);
}

.file-input {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.status-line {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.board-state-row {
  width: min(100%, 620px);
  margin: -2px auto 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.state-toggle {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 850;
  white-space: nowrap;
  cursor: pointer;
}

.orientation-toggle {
  background: rgba(226, 165, 45, 0.14);
  color: #825600;
}

.turn-toggle {
  margin-left: auto;
  background: rgba(15, 143, 123, 0.12);
  color: var(--accent-dark);
}

.board-stage {
  position: relative;
  width: min(100%, 620px, var(--board-size, calc(100dvh - 440px)));
  margin: 0 auto;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  margin: 0;
  border: 2px solid #252a31;
  border-radius: 8px;
  overflow: hidden;
  background: #252a31;
}

.loading-overlay {
  position: absolute;
  inset: 2px;
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 6px;
  background: rgba(251, 252, 254, 0.88);
  color: var(--ink);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.loading-overlay[hidden] {
  display: none;
}

.piece-loader {
  position: relative;
  width: 132px;
  height: 58px;
}

.loader-piece {
  position: absolute;
  bottom: 0;
  left: calc(var(--slot) * 22px);
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(32, 36, 45, 0.22));
  animation: piece-hop 1.15s ease-in-out infinite;
  animation-delay: calc(var(--slot) * 0.12s);
}

.loader-copy {
  color: var(--accent-dark);
  font-size: 0.86rem;
  font-weight: 900;
}

@keyframes piece-hop {
  0%,
  72%,
  100% {
    transform: translateY(0) scale(0.96);
    opacity: 0.66;
  }

  28% {
    transform: translateY(-14px) scale(1.08);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader-piece {
    animation: none;
  }
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  line-height: 1;
  box-shadow: none;
  cursor: pointer;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.board-coordinate {
  position: absolute;
  z-index: 2;
  font-size: clamp(6px, calc(var(--board-size, 416px) / 32), 13px);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.square.light .board-coordinate {
  color: var(--dark-square);
}

.square.dark .board-coordinate {
  color: var(--light-square);
}

.rank-coordinate {
  top: clamp(2px, calc(var(--board-size, 400px) / 80), 5px);
  left: clamp(2px, calc(var(--board-size, 400px) / 80), 5px);
}

.file-coordinate {
  right: clamp(2px, calc(var(--board-size, 400px) / 80), 5px);
  bottom: clamp(2px, calc(var(--board-size, 400px) / 80), 5px);
}

.square.low-confidence::after {
  content: "";
  position: absolute;
  z-index: 3;
  right: 5px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.piece-image {
  display: block;
  width: 92%;
  height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.28));
  pointer-events: none;
  user-select: none;
}

.edit-panel {
  width: min(100%, 620px);
  margin: 12px auto 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  display: grid;
  gap: 10px;
}

.editor-row,
.control-group {
  display: grid;
  gap: 7px;
}

.control-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
}

.piece-editor {
  --piece-tile-size: 44px;
  display: grid;
  gap: 8px;
}

.piece-side-row {
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(88px, 1.34fr);
  gap: 8px;
  align-items: start;
}

.piece-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.piece-button {
  display: grid;
  place-items: center;
  min-width: 0;
  height: 44px;
  aspect-ratio: auto;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.piece-button .piece-image {
  width: 40px;
  height: 40px;
}

.piece-button.empty-piece {
  aspect-ratio: 1;
  padding: 2px;
  color: var(--muted);
}

.empty-piece-slot {
  display: grid;
  align-self: stretch;
}

.empty-piece-slot .piece-button {
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 1;
}

.empty-icon {
  width: 68%;
  height: 68%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.piece-button.is-selected,
.toggle-button.is-active {
  border-color: var(--accent);
  background: rgba(15, 143, 123, 0.12);
  box-shadow: inset 0 0 0 1px rgba(15, 143, 123, 0.18);
}

.toggle-button:disabled,
.toggle-button.is-disabled {
  border-color: #d8dde6;
  background: #eef1f5;
  color: #8c94a3;
  box-shadow: none;
  cursor: not-allowed;
}

.castle-controls {
  display: grid;
  height: max(40px, var(--piece-tile-size));
  min-width: 0;
}

.castle-color-group {
  display: grid;
  align-content: stretch;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.castle-button-row {
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 6px;
  height: 100%;
  min-height: 0;
}

.toggle-button {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1.05;
  cursor: pointer;
}

.castle-button {
  min-height: 0;
  white-space: nowrap;
  padding: 0 5px;
  font-size: 0.78rem;
  letter-spacing: 0;
}

.piece-utility-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.remove-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  grid-column: 1;
  width: 100%;
  min-width: 0;
  justify-items: stretch;
}

.remove-control .control-label {
  width: 100%;
  text-align: left;
  font-size: 0.6rem;
}

.en-passant-control {
  display: grid;
  grid-column: 2;
  min-width: 0;
  gap: 6px;
}

.en-passant-control .control-label {
  font-size: 0.6rem;
}

.en-passant-select {
  width: 100%;
  min-height: 42px;
  height: 44px;
  -webkit-appearance: none;
  appearance: none;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='m5 7 5 5 5-5' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 10px center / 16px 16px no-repeat;
  color: var(--ink);
  font-weight: 750;
}

.analysis-actions {
  width: min(100%, 620px);
  margin: 12px auto 0;
}

.analysis-link {
  display: grid;
  place-items: center;
  min-height: 50px;
  width: 100%;
  border: 1px solid rgba(15, 143, 123, 0.45);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
  text-decoration: none;
}

.analysis-link.disabled {
  pointer-events: none;
  color: var(--muted);
  border-color: var(--line);
  background: #eef1f5;
}

.fen-actions {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  grid-column: 3;
}

.fen-action-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-size: 0.82rem;
  font-weight: 750;
  cursor: pointer;
}

.fen-action-button svg {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fen-copy-control {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.fen-copy-control .control-label {
  font-size: 0.6rem;
  text-align: center;
  text-transform: none;
  white-space: nowrap;
}

body:not(.native-mobile) .fen-copy-control > .control-label {
  visibility: hidden;
}

.fen-copy-button-label {
  white-space: nowrap;
}

.native-mobile .fen-copy-button-label {
  display: none;
}

.fen-action-button:disabled {
  color: var(--muted);
  background: #eef1f5;
  cursor: default;
}

.fen-action-button[hidden] {
  display: none;
}

@media (max-width: 560px) {
  .app-shell {
    gap: 10px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    column-gap: 8px;
    row-gap: 6px;
  }

  .title-block {
    display: contents;
  }

  .source-actions {
    grid-column: 2;
    grid-row: 1;
    grid-template-columns: 155px;
    grid-template-rows: 36px 36px;
    gap: 5px;
    width: auto;
  }

  .tagline-row {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .board-source-actions {
    gap: 6px;
  }

  .camera-action {
    display: grid;
  }

  .paste-action {
    display: none;
  }

  .info-card {
    padding: 14px;
  }

  .info-step {
    grid-template-columns: 22px minmax(72px, auto);
    column-gap: 12px;
    row-gap: 8px;
  }

  .info-step p {
    grid-column: 2 / -1;
  }

  .info-thumbnails {
    min-height: 40px;
  }

  .info-camera-thumbnail,
  .mobile-copy {
    display: grid;
  }

  .info-paste-thumbnail,
  .desktop-copy {
    display: none;
  }

  .brand-logo {
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 0;
    gap: 2px;
  }

  .coffee-link {
    width: 155px;
    height: 36px;
    margin-right: auto;
  }

  .edit-panel {
    width: 100%;
  }

  .piece-side-row {
    grid-template-columns: minmax(0, 6fr) minmax(88px, 1.34fr);
  }



  .remove-control .control-label {
    font-size: 0.6rem;
    text-align: left;
  }

.en-passant-control {
    margin-left: 0;
  }
}

@media (max-width: 380px) {
  .tagline {
    font-size: 0.84rem;
  }

  .info-action {
    width: 20px;
    height: 20px;
  }

  .info-action span {
    font-size: 16px;
  }

  .coffee-link {
    width: 136px;
    height: 34px;
  }

  .source-actions {
    grid-template-columns: 136px;
    grid-template-rows: 34px 34px;
  }

  .icon-action {
    width: 42px;
    height: 42px;
  }
}

.native-mobile .source-actions {
  grid-template-rows: var(--header-control-height);
  grid-template-columns: auto;
  align-self: center;
}

.native-mobile .contact-action {
  grid-row: 1;
}

.native-mobile .piece-side-row {
  display: contents;
}

.native-mobile .piece-editor {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.native-mobile .piece-row {
  grid-column: 1 / -1;
}

.native-mobile #whitePieceRow { grid-row: 1; }
.native-mobile #blackPieceRow { grid-row: 2; }
.native-mobile .castle-controls { grid-row: 3; height: 28px; }

.native-mobile .piece-button {
  min-height: 32px;
  aspect-ratio: auto;
  height: 32px;
}

.native-mobile .piece-button .piece-image { width: 28px; height: 28px; }

.native-mobile .empty-piece-slot .piece-button { height: 44px; }

.native-mobile .castle-button-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  grid-template-rows: 28px;
  height: 28px;
}

.native-mobile .castle-button { min-height: 28px; display: flex; justify-content: center; gap: 4px; padding-inline: 3px; font-size: 0.72rem; }
.native-mobile .castle-button::before {
  content: "";
  width: 12px;
  height: 16px;
  flex: 0 0 12px;
  background: url("assets/pieces/cburnett/wK.svg") center / contain no-repeat;
}
.native-mobile .castle-controls[aria-label="Black castling rights"] .castle-button::before {
  background-image: url("assets/pieces/cburnett/bK.svg");
}
.native-mobile .piece-utility-row { grid-column: 1 / -1; }

#contactOverlay {
  display: flex;
  top: var(--contact-visual-viewport-top, 0px);
  bottom: auto;
  height: var(--contact-visual-viewport-height, 100vh);
  height: var(--contact-visual-viewport-height, 100dvh);
  flex-direction: column;
  align-items: center;
  overflow: clip;
  overscroll-behavior: contain;
  scroll-padding-block: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom));
}

#contactOverlay[hidden] {
  display: none;
}

#contactOverlay .contact-card {
  max-height: calc(var(--contact-visual-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px);
  margin: auto 0;
  padding: 12px;
  overflow: visible;
  overscroll-behavior: contain;
  scroll-padding-block: 8px;
}

.contact-card .info-card-header { margin-bottom: 8px; gap: 8px; }

.contact-card .info-close-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
}

.contact-form textarea,
.contact-form input {
  padding: 8px;
  font-size: 16px;
}

.contact-form input { min-height: 40px; height: 40px; }

.contact-form textarea {
  min-height: 48px;
  height: clamp(48px, calc(var(--contact-visual-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 280px), 88px);
  resize: none;
}

.contact-form { gap: 6px; }
.contact-form label { font-size: 0.82rem; line-height: 1.2; }
.contact-note { font-size: 0.75rem; line-height: 1.2; }

.contact-send-button {
  min-height: 44px;
  margin-top: 0;
}

#contactOverlay.is-compact .contact-card { padding: 10px; }
#contactOverlay.is-compact .info-card-header { margin-bottom: 6px; }
#contactOverlay.is-compact .info-close-button { width: 36px; height: 36px; flex-basis: 36px; }
#contactOverlay.is-compact .contact-form { gap: 4px; }
#contactOverlay.is-compact .contact-form textarea { height: 48px; }
#contactOverlay.is-compact .contact-form input { min-height: 36px; height: 36px; }
#contactOverlay.is-compact .contact-form label { font-size: 0.78rem; }
#contactOverlay.is-compact .contact-note { display: none; }
#contactOverlay.is-compact .contact-send-button { min-height: 40px; }

@media (min-width: 560px) {
  #contactOverlay.is-compact .contact-form { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; }
  #contactOverlay.is-compact label[for="contactMessage"] { grid-column: 1; grid-row: 1; }
  #contactOverlay.is-compact #contactMessage { grid-column: 1; grid-row: 2; }
  #contactOverlay.is-compact label[for="contactEmail"] { grid-column: 2; grid-row: 1; }
  #contactOverlay.is-compact #contactEmail { grid-column: 2; grid-row: 2; height: 48px; }
  #contactOverlay.is-compact .contact-form-status,
  #contactOverlay.is-compact .contact-send-button { grid-column: 1 / -1; }
}

#contactOverlay:has(.contact-form-status:not([hidden])) textarea {
  min-height: 36px;
  height: clamp(36px, calc(var(--contact-visual-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 320px), 88px);
}
#contactOverlay.is-compact:has(.contact-form-status:not([hidden])) textarea,
#contactOverlay.is-compact:has(.contact-form-status:not([hidden])) #contactEmail { height: 36px; }

/* Compact header and editor keep usable targets while leaving room for the board. */
@media (max-width: 560px) {
  .app-shell { gap: 6px; }
  .topbar { padding: 4px 2px; align-items: center; }
  .brand-logo { flex-direction: row; align-items: center; gap: 6px; }
  .brand-name { font-size: clamp(0.875rem, 4vw, 1.125rem); }
  .tagline { font-size: 0.76rem; }
  .source-actions { grid-template-columns: 108px; }
  .coffee-link { width: 108px; }
  .panel { padding: 8px; }
  .section-heading { margin-bottom: 6px; }
  .board-stage { width: min(100%, var(--board-size, 100%)); }
  .board-state-row { margin: 0 auto 6px; }
  .state-toggle { min-height: 32px; padding-inline: 10px; font-size: 0.78rem; }
  .analysis-actions { margin-top: 6px; }
  .analysis-link { min-height: 36px; }
  .edit-panel { padding: 6px; margin-top: 6px; gap: 4px; }
  .editor-row, .piece-editor { gap: 4px; }
  .piece-row { gap: 4px; }
  .piece-button { height: 32px; aspect-ratio: auto; }
  .piece-button .piece-image { width: 28px; height: 28px; }
  .piece-button.empty-piece { aspect-ratio: auto; }
  .empty-piece-slot .piece-button { height: 36px; aspect-ratio: auto; }
  .native-mobile .empty-piece-slot .piece-button { height: 36px; }
  .piece-utility-row { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 6px; }
  .remove-control, .en-passant-control, .fen-copy-control { gap: 4px; }
  .en-passant-select { min-height: 36px; height: 36px; padding-left: 8px; }
  .fen-action-button { min-width: 36px; min-height: 36px; padding: 4px 8px; }
}

@media (max-width: 360px) {
  .app-shell { padding-left: calc(6px + env(safe-area-inset-left)); padding-right: calc(6px + env(safe-area-inset-right)); }
  .panel { padding: 8px; }
  .edit-panel { padding: 6px; }
  .native-mobile .piece-row { gap: 2px; }
  .piece-utility-row { gap: 6px; }
  .status-line { font-size: 0.76rem; }
}

@media (max-width: 559px) and (max-height: 700px) {
  .app-shell { gap: 4px; padding-top: calc(4px + env(safe-area-inset-top)); }
  .topbar { padding-block: 2px; row-gap: 4px; }
  .section-heading { margin-bottom: 6px; }
  .board-state-row { margin-bottom: 6px; }
  .analysis-actions { margin-top: 6px; }
  .edit-panel { margin-top: 6px; padding: 6px; }
  .editor-row > .control-label { display: none; }
  .editor-row { gap: 0; }
}

/* Short landscape windows place the editor beside the board. */
@media (min-width: 560px) and (max-height: 600px) {
  .app-shell { gap: 6px; }
  .topbar { align-items: center; }
  .brand-logo { margin-bottom: 4px; }
  .brand-name { font-size: 1.125rem; }
  .tagline { font-size: 0.76rem; }
  .source-actions { grid-template-columns: 124px auto; grid-template-rows: var(--header-control-height); gap: 8px; }
  .coffee-link { width: 124px; height: 36px; }
  .contact-action { grid-column: 2; grid-row: 1; }
  .board-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 6px 12px;
    align-content: start;
    align-items: start;
    padding: 8px;
  }
  .section-heading { grid-column: 1; grid-row: 1; margin-bottom: 0; }
  .board-state-row { grid-column: 1; grid-row: 2; margin: 0 auto; }
  .board-stage { grid-column: 1; grid-row: 3; }
  .analysis-actions { grid-column: 1; grid-row: 4; margin: 0 auto; }
  .analysis-link { min-height: 44px; }
  .edit-panel { grid-column: 2; grid-row: 1 / 5; margin: 0; padding: 6px; }
  .editor-row > .control-label { display: none; }
  .editor-row { gap: 0; }
  .piece-side-row { grid-template-columns: minmax(0, 6fr) minmax(70px, 1.34fr); }
  .state-toggle { min-height: 32px; padding-inline: 6px; font-size: 0.7rem; }
  .native-mobile .piece-row { gap: 2px; }
  .native-mobile .source-actions { grid-template-columns: auto; grid-template-rows: var(--header-control-height); }
  .native-mobile .contact-action { grid-column: 1; }
}

@media (min-width: 560px) and (max-height: 360px) {
  .board-panel { padding: 6px; }
}

/* Use the same layout when a short visible viewport needs controls beside the
   board, including narrow windows and a keyboard reducing the visible height. */
.app-shell.is-wide-short { width: min(1120px, 100%); gap: 6px; }
.is-wide-short .topbar { align-items: center; }
.is-wide-short .brand-logo { flex-direction: row; align-items: center; margin-bottom: 4px; }
.is-wide-short .brand-name { font-size: clamp(0.875rem, 3vw, 1.125rem); }
.is-wide-short .tagline { font-size: 0.76rem; }
.is-wide-short .source-actions { grid-template-columns: 124px auto; grid-template-rows: var(--header-control-height); gap: 8px; }
.is-wide-short .coffee-link { width: 124px; height: 36px; }
.is-wide-short .contact-action { grid-column: 2; grid-row: 1; }
.is-wide-short .board-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.62fr);
  gap: 6px 12px;
  align-content: start;
  align-items: start;
  padding: 8px;
}
.is-wide-short .section-heading { grid-column: 2; grid-row: 1; margin-bottom: 0; }
.is-wide-short .board-state-row { grid-column: 1; grid-row: 1; width: 100%; align-self: center; margin: 0 auto; gap: 4px; }
.is-wide-short .board-stage { grid-column: 1; grid-row: 2; width: min(100%, var(--board-size, 100%)); }
.is-wide-short .analysis-actions { grid-column: 1; grid-row: 3; width: 100%; margin: 0 auto; }
.is-wide-short .analysis-link { min-height: 36px; }
.is-wide-short .edit-panel { grid-column: 2; grid-row: 2 / 4; margin: 0; padding: 6px; }
.is-wide-short .editor-row > .control-label { display: none; }
.is-wide-short .editor-row { gap: 0; }
.is-wide-short .piece-side-row { grid-template-columns: minmax(0, 6fr) minmax(70px, 1.34fr); }
.is-wide-short .state-toggle { min-height: 28px; padding-inline: 6px; font-size: 0.7rem; }
.is-wide-short .piece-row { gap: 2px; }
.native-mobile .is-wide-short .source-actions { grid-template-columns: auto; grid-template-rows: var(--header-control-height); }
.native-mobile .is-wide-short .contact-action { grid-column: 1; }

.app-shell.is-tight { --header-control-height: 32px; gap: 4px; }
.is-tight .topbar { padding-block: 2px; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; align-items: center; }
.is-tight .title-block { display: contents; }
.is-tight .brand-logo { grid-column: 1; grid-row: 1; margin-bottom: 0; }
.is-tight .tagline-row { grid-column: 2; grid-row: 1; }
.is-tight .tagline { display: none; }
.is-tight .source-actions { grid-column: 3; grid-row: 1; }
.is-tight .board-panel { padding: 6px; gap: 4px 8px; }
.is-tight .section-heading { gap: 4px; }
.is-tight .icon-action { width: 32px; height: 32px; }
.is-tight .board-source-actions { gap: 4px; }
.is-tight .analysis-link { min-height: 32px; font-size: 0.82rem; }
.is-tight .piece-button { min-height: 28px; height: 28px; }
.is-tight .piece-button .piece-image { width: 24px; height: 24px; }
.is-tight .edit-panel { padding: 6px; gap: 4px; }

@media (max-width: 559px) {
  .is-wide-short .board-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
  .is-wide-short .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .is-wide-short .source-actions { grid-template-columns: auto; grid-template-rows: var(--header-control-height); }
  .is-wide-short .contact-action { grid-column: 1; }
  .is-wide-short .coffee-link { display: none; }
  .is-wide-short .section-heading { flex-direction: column; align-items: stretch; }
  .is-wide-short .section-heading h2 { display: none; }
  .is-wide-short .status-line { font-size: 0.7rem; -webkit-line-clamp: 1; }
  .is-wide-short .board-source-actions { justify-content: center; }
  .is-wide-short .board-state-row { flex-wrap: wrap; justify-content: center; }
  .is-wide-short .state-toggle { min-height: 24px; font-size: 0.63rem; padding-inline: 4px; }
  .is-wide-short .turn-toggle { margin-left: 0; }
  .is-wide-short .piece-side-row { display: contents; }
  .is-wide-short .piece-editor { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .is-wide-short .piece-row { grid-column: 1 / -1; }
  .is-wide-short #whitePieceRow { grid-row: 1; }
  .is-wide-short #blackPieceRow { grid-row: 2; }
  .is-wide-short .castle-controls { grid-row: 3; height: 24px; }
  .is-wide-short .castle-button-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: 24px; height: 24px; gap: 2px; }
  .is-wide-short .castle-button { min-height: 24px; padding-inline: 1px; font-size: 0.6rem; }
  .is-wide-short .castle-button::before { display: none; }
  .is-wide-short .piece-utility-row { grid-column: 1 / -1; grid-template-columns: 44px minmax(0, 1fr); gap: 6px; }
  .is-wide-short .fen-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .is-wide-short .fen-copy-control { grid-template-columns: auto auto; align-items: center; gap: 6px; }
  .is-wide-short .fen-action-button { min-height: 32px; min-width: 32px; padding: 4px 6px; }
  .is-wide-short .fen-copy-control > .control-label { visibility: visible; }
  .is-wide-short .fen-copy-button-label { display: none; }
  .is-wide-short .en-passant-select { padding-right: 24px; font-size: 0.8rem; background-position: right 5px center; }
}

.edit-panel { container-type: inline-size; }
.piece-button .piece-image { max-width: 100%; max-height: 100%; }
@container (max-width: 250px) {
  .piece-utility-row { gap: 6px; }
  .en-passant-select { padding-left: 8px; padding-right: 20px; font-size: 0.8rem; background-size: 12px 12px; background-position: right 4px center; }
  .fen-action-button { min-width: 32px; min-height: 36px; padding: 4px 6px; }
  .fen-copy-control > .control-label { visibility: visible !important; }
  .fen-copy-button-label { display: none; }
  .fen-actions { gap: 4px; }
}
@container (max-width: 200px) {
  .piece-utility-row { grid-template-columns: 44px minmax(0, 1fr); }
  .fen-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

.about-link { display: block; width: max-content; margin-top: 10px; font-size: 0.8rem; color: var(--accent-dark); }
.info-overlay { top: var(--contact-visual-viewport-top, 0px); bottom: auto; height: var(--contact-visual-viewport-height, 100dvh); padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom)); }
#infoOverlay .info-card { padding: 12px; }
#infoOverlay .info-card-header { margin-bottom: 8px; }
#infoOverlay .info-steps { gap: 8px; }
#infoOverlay .info-step { grid-template-columns: 22px minmax(0, 1fr); gap: 4px 8px; }
#infoOverlay .info-thumbnails { display: none; }
#infoOverlay .info-step p { grid-column: 2; font-size: 0.8rem; line-height: 1.3; }
@media (max-height: 480px) {
  #infoOverlay .info-card { width: min(100%, 680px); }
  #infoOverlay .info-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #infoOverlay .info-step { align-content: start; align-items: start; }
}
#infoOverlay.is-compact .info-card { width: min(100%, 680px); }
#infoOverlay.is-compact .info-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#infoOverlay.is-compact .info-step { align-content: start; align-items: start; }
#infoOverlay.is-compact .info-step p { font-size: 0.72rem; line-height: 1.25; }

#contactOverlay.is-compressed .contact-card { padding: 8px; }
#contactOverlay.is-compressed .info-card-header { margin-bottom: 2px; }
#contactOverlay.is-compressed .info-close-button { width: 24px; height: 24px; flex-basis: 24px; }
#contactOverlay.is-compressed .contact-form { grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; align-items: center; }
#contactOverlay.is-compressed label[for="contactMessage"] { grid-column: 1; grid-row: 1; }
#contactOverlay.is-compressed #contactMessage { grid-column: 2; grid-row: 1; }
#contactOverlay.is-compressed label[for="contactEmail"] { grid-column: 1; grid-row: 2; }
#contactOverlay.is-compressed #contactEmail { grid-column: 2; grid-row: 2; min-height: 28px; height: 28px; }
#contactOverlay.is-compressed .contact-form-status,
#contactOverlay.is-compressed .contact-send-button { grid-column: 1 / -1; }
#contactOverlay.is-compressed .contact-form label { font-size: 0.7rem; line-height: 1; }
#contactOverlay.is-compressed .contact-form label span { font-size: inherit; }
#contactOverlay.is-compressed .contact-form textarea { min-height: 28px; height: 28px; padding: 3px 4px; }
#contactOverlay.is-compressed .contact-form input { min-height: 28px; height: 28px; padding: 3px 4px; }
#contactOverlay.is-compressed .contact-send-button { min-height: 28px; height: 28px; font-size: 0.8rem; }
#contactOverlay.is-compressed .contact-form-status { font-size: 0.7rem; line-height: 1.1; margin: 0; }
#contactOverlay.is-compressed:has(.contact-form-status:not([hidden])) textarea,
#contactOverlay.is-compressed:has(.contact-form-status:not([hidden])) #contactEmail { height: 28px; }

.about-panel {
  width: 100%;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(32, 36, 45, 0.06);
  line-height: 1.55;
}

.about-panel h2 {
  font-size: 1.12rem;
}

.about-panel h3 {
  margin: 18px 0 0;
  font-size: 0.98rem;
}

.about-panel p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.about-panel ol {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.92rem;
}

.about-panel li + li {
  margin-top: 4px;
}

.faq-list {
  margin: 8px 0 0;
}

.faq-list dt {
  margin-top: 10px;
  font-size: 0.92rem;
  font-weight: 750;
}

.faq-list dd {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

/* Phones and tablets retain Library and Camera; clipboard import is desktop only. */
@media (pointer: coarse) {
  .paste-action,
  .desktop-copy { display: none; }
  .mobile-copy { display: grid; }
  .camera-action { display: grid; }
}
