/* CheckersCraft — senior-friendly, offline-first */

:root {
  --accent: #9A3412;
  --accent-hover: #C2410C;
  --accent-soft: #FFEDD5;
  --accent-ink: #7C2D12;
  --bg: #F7F4EF;
  --surface: #FFFFFF;
  --surface-2: #F0EBE3;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D3D1;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 980px;
  --board-light: #F5E6D3;
  --board-dark: #8B5E3C;
  --piece-dark: #1C1917;
  --piece-light: #F8FAFC;
  --piece-dark-ring: #FBBF24;
  --piece-light-ring: #9A3412;
  --move-hint: rgba(34, 197, 94, 0.55);
  --select-glow: rgba(251, 191, 36, 0.75);
  --last-move: rgba(251, 191, 36, 0.35);
}

:root[data-theme="felt"] {
  --board-light: #E8F5E9;
  --board-dark: #2E7D32;
  --piece-dark: #111827;
  --piece-light: #FFFBEB;
}

:root[data-theme="high"] {
  --board-light: #FFFFFF;
  --board-dark: #111827;
  --piece-dark: #000000;
  --piece-light: #FFFFFF;
  --piece-dark-ring: #FBBF24;
  --piece-light-ring: #EF4444;
  --text: #000000;
  --bg: #FFFFFF;
  --border: #44403C;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.35rem;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 3px var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.main-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.65rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.nav-btn.is-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  width: 100%;
  flex: 1;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
  color: var(--accent-ink);
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 48ch;
}

.row-between {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
}

/* Cards & components */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card h3 {
  margin: 0 0 0.65rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.card-head h3 {
  margin: 0;
}

.sample-card {
  border-color: #FDBA74;
  background: linear-gradient(180deg, #FFF7ED 0%, #FFFFFF 55%);
}

.help-text,
.muted {
  color: var(--text-muted);
}

.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.field.grow {
  flex: 1;
  min-width: 12rem;
}

.field input[type="text"],
.field input[type="search"],
.field input[type="date"],
.field select,
.field textarea,
.backup-text {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.field textarea,
.backup-text {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.backup-text:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--touch);
}

.check-field input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.check-field label {
  margin: 0;
  font-weight: 500;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem 1rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.btn {
  min-height: var(--touch);
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: #FDBA74;
}

.btn-secondary:hover:not(:disabled) {
  background: #FED7AA;
}

.btn-text {
  background: transparent;
  color: var(--accent-ink);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover:not(:disabled) {
  background: var(--surface-2);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #FECACA;
}

.btn-danger:hover:not(:disabled) {
  background: #FECACA;
}

.btn-sm {
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  font-size: 0.95rem;
}

/* Play layout */
.play-layout {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .play-layout {
    grid-template-columns: 1fr 300px;
    grid-template-areas:
      "controls controls"
      "board coach";
    align-items: start;
  }

  .play-controls {
    grid-area: controls;
  }

  .board-panel {
    grid-area: board;
  }

  .coach-panel {
    grid-area: coach;
    position: sticky;
    top: 7.5rem;
  }
}

.status-banner {
  margin: 0.85rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  border: 1px solid #FDBA74;
}

.status-banner.is-win {
  background: var(--success-soft);
  color: var(--success);
  border-color: #86EFAC;
}

.status-banner.is-loss {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #FECACA;
}

.status-banner.is-draw {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #FCD34D;
}

.board-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.turn-label {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.capture-note {
  margin: 0;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.95rem;
}

.board-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.25rem;
}

.board {
  --size: 8;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  width: min(100%, 560px);
  margin: 0 auto;
  aspect-ratio: 1;
  border: 4px solid #5D4037;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  background: #5D4037;
  user-select: none;
  touch-action: manipulation;
}

.board[data-size="10"] {
  width: min(100%, 640px);
}

.board[data-size="12"] {
  width: min(100%, 720px);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: none;
  padding: 0;
  background: var(--board-light);
  aspect-ratio: 1;
}

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

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

.square.is-selected {
  box-shadow: inset 0 0 0 4px var(--select-glow);
}

.square.is-target::after {
  content: "";
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--move-hint);
  box-shadow: 0 0 0 2px rgba(22, 101, 52, 0.5);
}

.square.is-target.has-piece::after {
  width: 72%;
  height: 72%;
  background: transparent;
  border: 4px solid #16A34A;
  box-shadow: none;
}

.square.is-last {
  box-shadow: inset 0 0 0 3px var(--last-move);
}

.square.is-focus {
  outline: 3px solid #fff;
  outline-offset: -3px;
  z-index: 1;
}

.square .coord {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 700;
  opacity: 0.7;
  pointer-events: none;
  line-height: 1;
  color: inherit;
}

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

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

.coord-file {
  bottom: 2px;
  right: 3px;
}

.coord-rank {
  top: 2px;
  left: 3px;
}

.piece {
  width: 72%;
  height: 72%;
  max-width: 56px;
  max-height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(0.65rem, 2.2vw, 0.95rem);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 2px 3px rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.piece.dark-piece {
  background: radial-gradient(circle at 35% 30%, #44403C, var(--piece-dark) 55%);
  color: #FBBF24;
  border: 3px solid var(--piece-dark-ring);
}

.piece.light-piece {
  background: radial-gradient(circle at 35% 30%, #FFFFFF, var(--piece-light) 60%);
  color: var(--piece-light-ring);
  border: 3px solid var(--piece-light-ring);
}

.piece.king::before {
  content: "★";
  font-size: 1.05em;
  line-height: 1;
}

.board-help {
  margin: 0.85rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
}

.coach-feed {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.coach-tip {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
}

.coach-tip strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--accent-ink);
}

.coach-tip p {
  margin: 0;
  color: var(--text);
}

/* Lists */
.item-list,
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.item-card.sample-item {
  border-style: dashed;
  border-color: #FDBA74;
}

.item-card h3,
.item-card h4 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  color: var(--accent-ink);
}

.item-meta {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.item-body {
  margin: 0 0 0.75rem;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-right: 0.35rem;
}

.badge-win {
  background: var(--success-soft);
  color: var(--success);
}

.badge-loss {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-draw {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-sample {
  background: #FEF3C7;
  color: #92400E;
}

.variant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}

.variant-card.is-fav {
  border-color: #FDBA74;
  background: linear-gradient(180deg, #FFF7ED 0%, #fff 40%);
}

.variant-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.variant-card p {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
}

.variant-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.tag {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.variant-detail p {
  margin: 0 0 0.75rem;
}

.variant-detail dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
}

.variant-detail dt {
  font-weight: 700;
  color: var(--accent-ink);
}

.variant-detail dd {
  margin: 0;
  color: var(--text-muted);
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stat-card.stat-accent {
  background: var(--accent-soft);
  border-color: #FDBA74;
}

.stat-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.stat-value {
  margin: 0.25rem 0 0;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent-ink);
  line-height: 1.1;
}

.two-col {
  display: grid;
  gap: 1rem;
}

@media (min-width: 700px) {
  .two-col {
    grid-template-columns: 1fr 1fr;
  }
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.plain-list li:last-child {
  border-bottom: none;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.bar-label {
  min-width: 4.5rem;
  font-weight: 600;
}

.bar-track {
  flex: 1;
  height: 14px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 2px;
}

.bar-count {
  min-width: 2rem;
  text-align: right;
  font-weight: 700;
  color: var(--text-muted);
}

.rhythm-panel {
  display: grid;
  gap: 0.5rem;
}

.lesson-card.is-done {
  border-color: #86EFAC;
  background: linear-gradient(180deg, #F0FDF4 0%, #fff 50%);
}

.goal-item.is-done .item-body {
  text-decoration: line-through;
  color: var(--text-muted);
}

.empty-msg {
  margin: 0.5rem 0;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.status-msg {
  margin: 0.65rem 0 0;
  font-weight: 600;
  color: var(--accent-ink);
  min-height: 1.4em;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--text);
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: min(92vw, 420px);
  text-align: center;
  font-weight: 600;
}

.toast[hidden] {
  display: none !important;
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(92vw, 480px);
  width: 100%;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
}

.modal.modal-wide {
  max-width: min(92vw, 560px);
}

.modal::backdrop {
  background: rgba(28, 25, 23, 0.45);
}

.modal-inner {
  padding: 1.35rem 1.35rem 1.15rem;
}

.modal-inner h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  color: var(--accent-ink);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem 1.25rem 1.75rem;
  text-align: center;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  font-size: 0.95rem;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
