:root {
  color-scheme: light dark;
  --bg: #f4efe6;
  --panel: #fffdf8;
  --text: #1f1a17;
  --muted: #6d645c;
  --accent: #2f6fed;
  --accent-dark: #1f4eb0;
  --border: #ddd2c4;
  --error: #b42318;
  --light-square: #ebddc5;
  --dark-square: #b58863;
  --shadow: 0 10px 30px rgba(31, 26, 23, 0.08);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(47, 111, 237, 0.12), transparent 35%),
    var(--bg);
  color: var(--text);
}

.page {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 2.8rem);
}

.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 70ch;
  line-height: 1.6;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(320px, 1fr);
  gap: 24px;
  align-items: start;
}

.panel,
.output {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.panel h2,
.output h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.field-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

button {
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  background: var(--accent);
  color: white;
  font-weight: 600;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: rgba(47, 111, 237, 0.08);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.actions button {
  flex: 1;
}

.hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.output {
  padding: 20px;
}

.stats {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(47, 111, 237, 0.08);
  line-height: 1.5;
}

.stats.error {
  background: rgba(180, 35, 24, 0.08);
  color: var(--error);
}

.meta {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.meta-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  align-items: center;
}

.meta-row strong {
  color: var(--muted);
  font-size: 0.9rem;
}

.fen-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.fen-row pre {
  flex: 1;
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f7f2ea;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(36px, 1fr));
  width: min(100%, 420px);
  aspect-ratio: 1;
  border: 6px solid #5c4632;
  border-radius: 8px;
  overflow: hidden;
}

.square {
  display: grid;
  place-items: center;
  user-select: none;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.piece {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  line-height: 1;
}

.white-piece {
  color: #ffffff;
  -webkit-text-stroke: 1.2px #1f1a17;
  paint-order: stroke fill;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.black-piece {
  color: #1f1a17;
  -webkit-text-stroke: 1.2px #ffffff;
  paint-order: stroke fill;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Sidebar split layout gap */
.sidebar-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Clickable board squares */
.board [data-square$="1"],
.board [data-square$="8"] {
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.board [data-square$="1"]:hover,
.board [data-square$="8"]:hover {
  filter: brightness(0.95);
  box-shadow: inset 0 0 0 3px var(--accent);
}

/* Constrained square indicator dot */
.square.constrained {
  position: relative;
}

.square.constrained::after {
  content: '';
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 9px;
  height: 9px;
  background-color: var(--accent);
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

/* Piece Selector Popover */
.piece-selector-popover {
  position: absolute;
  z-index: 1000;
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(31, 26, 23, 0.15), 0 0 1px rgba(31, 26, 23, 0.1);
  transform: translate(-50%, -100%);
  animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -90%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -100%) scale(1);
  }
}

.piece-selector-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #1f1a17;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.piece-selector-btn:hover {
  background: rgba(47, 111, 237, 0.08);
  transform: translateY(-2px);
}

.piece-selector-btn.clear-btn {
  color: var(--error);
  font-weight: bold;
  font-size: 1.2rem;
}

.piece-selector-btn.clear-btn:hover {
  background: rgba(180, 35, 24, 0.08);
}

.board-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  width: min(100%, 420px);
}

.board-actions button {
  flex: 1;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .output {
    grid-row: 1;
  }

  .sidebar-form {
    grid-row: 2;
  }

  .board {
    width: min(100%, 360px);
  }

  .board-actions {
    width: min(100%, 360px);
  }
}

/* Guide Section (SEO Content) styling */
.guide-section {
  margin-top: 48px;
  padding-top: 36px;
  border-top: 1px solid var(--border);
}

.guide-section h2 {
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  margin-bottom: 24px;
  text-align: center;
  color: var(--text);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

.guide-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.guide-card h3 {
  font-size: 1.15rem;
  margin-top: 0;
  margin-bottom: 14px;
  color: var(--accent-dark);
  border-left: 4px solid var(--accent);
  padding-left: 10px;
}

.guide-card p {
  font-size: 0.94rem;
  line-height: 1.6;
  color: var(--text);
  margin-top: 0;
  margin-bottom: 12px;
}

.guide-card ul {
  padding-left: 20px;
  margin: 10px 0;
}

.guide-card li {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 8px;
}

.guide-sub-text {
  font-size: 0.84rem !important;
  color: var(--muted) !important;
  background: rgba(47, 111, 237, 0.04);
  border-radius: 8px;
  padding: 10px;
  border: 1px dashed var(--border);
}

/* Footer styling */
.footer {
  background: #1f1a17;
  color: #fffdf8;
  padding: 28px 0;
  margin-top: 60px;
  border-top: 4px solid #5c4632;
}

.footer-content {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer p {
  margin: 0;
  font-size: 0.88rem;
  color: #a39990;
}

.footer-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.footer-links a {
  color: #ebddc5;
  text-decoration: none;
  font-size: 0.88rem;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: #ffffff;
  text-decoration: underline;
}

.footer-links .sep {
  color: #5c4632;
  font-size: 0.8rem;
}

/* Policy subpage layout adjustments */
.policy-page .hero {
  text-align: center;
  margin-bottom: 30px;
}

.policy-content h2 {
  font-size: 1.25rem;
  margin-top: 24px;
  margin-bottom: 12px;
  color: var(--accent-dark);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.policy-content p, 
.policy-content li {
  line-height: 1.7;
  color: var(--text);
}

.policy-content a {
  color: var(--accent);
  text-decoration: none;
}

.policy-content a:hover {
  text-decoration: underline;
}

/* Return home button styling inside policy pages */
.policy-page .button {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 12px 24px;
  font-weight: 600;
  transition: background 0.2s;
}

.policy-page .button:hover {
  background: var(--accent-dark);
}

@media (max-width: 600px) {
  .footer-content {
    flex-direction: column;
    text-align: center;
  }
}
