/* Tishvi Chess Companion — app shell styles */

@font-face {
  font-family: 'Crimson Text';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/crimsontext-normal-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Crimson Text';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/crimsontext-normal-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Crimson Text';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/crimsontext-normal-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Crimson Text';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/crimsontext-italic-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/lato-normal-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/lato-normal-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/lato-italic-400.woff2') format('woff2');
}

:root {
  --tishvi-green:      #1F4A38;
  --tishvi-green-lt:   #DCE7E1;
  --tishvi-cream:      #EDE6D6;
  --tishvi-paper:      #F1EFE8;
  --tishvi-ink:        #1E1E1E;
  --tishvi-rule:       #B7B7B7;
  --tishvi-grey:       #777777;
  --tishvi-diagram:    #E8E5DC;
  /* Darker than the brand grey specifically for small body text on
     --tishvi-paper: #777777 there measures ~3.9:1, below WCAG AA's 4.5:1
     for normal text. This is text-only; --tishvi-grey (~3.9:1, fine for a
     3:1 UI-component/border threshold) is unchanged for hairlines etc. */
  --tishvi-grey-text:  #5C5C5C;

  --font-heading: 'Crimson Text', Georgia, serif;
  --font-body: 'Lato', -apple-system, sans-serif;

  --touch-target: 44px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--tishvi-paper);
  color: var(--tishvi-ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--tishvi-green);
  margin: 0 0 0.5em 0;
  font-weight: 600;
}

.wordmark {
  font-family: var(--font-body);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
}

a {
  color: var(--tishvi-green);
}

button {
  font-family: var(--font-body);
  font-size: 1rem;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  border-radius: 8px;
  border: 1px solid var(--tishvi-rule);
  background: var(--tishvi-paper);
  color: var(--tishvi-ink);
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--tishvi-green);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--tishvi-green);
  color: var(--tishvi-cream);
  border-color: var(--tishvi-green);
  font-weight: 700;
  padding: 0 20px;
}

.app-header {
  background: var(--tishvi-green);
  color: var(--tishvi-cream);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .wordmark {
  color: var(--tishvi-cream);
  font-size: 1.1rem;
}

.env-badge {
  margin-left: auto;
  padding: 2px 10px;
  border: 1px solid var(--tishvi-cream);
  border-radius: 999px;
  color: var(--tishvi-cream);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Anything that isn't Production stands out so it's never mistaken for it. */
.env-badge[data-env='pre-prod'],
.env-badge[data-env='local'] {
  background: var(--tishvi-cream);
  color: var(--tishvi-green);
}

main {
  padding: 20px;
  max-width: 480px;
  margin: 0 auto;
}

.panel {
  background: var(--tishvi-green-lt);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.offline-note {
  color: var(--tishvi-grey-text);
  font-size: 0.9rem;
}

.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;
}

.link-btn {
  background: none;
  border: none;
  color: var(--tishvi-green);
  font-weight: 700;
  padding: 8px 4px;
  margin-bottom: 8px;
}

/* ---------- Capture screen ---------- */

.capture-screen {
  max-width: 480px;
  margin: 0 auto;
}

.capture-guidance {
  color: var(--tishvi-grey-text);
  margin-bottom: 20px;
}

.capture-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.capture-buttons button {
  width: 100%;
}

.capture-preview img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--tishvi-rule);
  display: block;
}

.capture-preview-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.capture-preview-actions button {
  flex: 1;
}

/* ---------- Transcribe split layout ---------- */

.transcribe-layout {
  max-width: 480px;
  margin: 0 auto;
}

.entry-panel {
  padding-top: 4px;
}

/* ---------- Photo viewer ---------- */

.photo-panel {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--tishvi-paper);
  padding: 8px 0;
  border-bottom: 1px solid var(--tishvi-rule);
  margin-bottom: 16px;
}

.photo-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.photo-controls button {
  padding: 0 12px;
  min-height: var(--touch-target);
}

.photo-controls .zoom-btn {
  width: var(--touch-target);
  padding: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
}

.photo-controls label {
  font-size: 0.8rem;
  color: var(--tishvi-grey-text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.photo-controls input[type='range'] {
  width: 72px;
}

.photo-viewport {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #111;
  height: min(46vh, 420px);
  min-height: 220px;
  touch-action: none;
  transition: height 0.2s ease;
}

.photo-panel.collapsed .photo-viewport {
  height: 0;
}

.photo-viewport img {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  max-width: none;
  will-change: transform;
  user-select: none;
}

/* ---------- Game status ---------- */

.game-status {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--tishvi-green);
  margin: 0 0 12px 0;
  min-height: 1.4em;
}

/* ---------- Board ---------- */

.board-container {
  margin-bottom: 16px;
}

.board-frame {
  display: grid;
  grid-template-columns: 18px 1fr;
  grid-template-rows: 1fr 18px;
  gap: 4px;
  max-width: 420px;
  margin: 0 auto;
}

.board-ranks {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
}

.board-ranks span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--tishvi-grey-text);
}

.board-files {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
}

.board-files span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--tishvi-grey-text);
}

.board-corner {
  grid-column: 1;
  grid-row: 2;
}

.board {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  border: 2px solid var(--tishvi-green);
  border-radius: 4px;
  overflow: hidden;
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 5vw, 28px);
  cursor: pointer;
}

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

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

.square.selected {
  outline: 3px solid var(--tishvi-green);
  outline-offset: -3px;
}

.square.last-move {
  background-image: linear-gradient(rgba(31, 74, 56, 0.18), rgba(31, 74, 56, 0.18));
}

.square.in-check {
  background-image: linear-gradient(rgba(178, 47, 37, 0.35), rgba(178, 47, 37, 0.35));
}

.square.legal-dest::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(31, 74, 56, 0.4);
}

.square.legal-dest.legal-capture::after {
  width: 80%;
  height: 80%;
  background: transparent;
  border: 3px solid rgba(178, 47, 37, 0.55);
  border-radius: 50%;
}

.piece {
  line-height: 1;
  pointer-events: none;
}

.piece-black {
  color: var(--tishvi-ink);
}

.piece-white {
  color: var(--tishvi-cream);
  -webkit-text-stroke: 1px var(--tishvi-ink);
}

/* ---------- Move input ---------- */

.move-input {
  margin-bottom: 16px;
}

.move-input input {
  width: 100%;
  min-height: var(--touch-target);
  padding: 0 12px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  font-size: 1rem;
  font-family: var(--font-body);
  background: #fff;
  color: var(--tishvi-ink);
}

.move-suggestions {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.move-chip {
  min-height: var(--touch-target);
  padding: 0 16px;
  border-radius: 22px;
  border: 1px solid var(--tishvi-green);
  background: var(--tishvi-green-lt);
  color: var(--tishvi-green);
  font-weight: 700;
}

.move-chip-suggestion {
  background: #fff;
  border-color: var(--tishvi-grey);
}

.move-feedback {
  margin: 8px 0 0 0;
  font-size: 0.9rem;
  color: var(--tishvi-grey-text);
}

/* ---------- Move list ---------- */

.move-list-wrap {
  margin-bottom: 16px;
}

.move-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.move-count {
  color: var(--tishvi-grey-text);
  font-size: 0.9rem;
}

.undo-btn {
  padding: 0 14px;
}

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

table.move-list {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table.move-list th,
table.move-list td {
  border-bottom: 1px solid var(--tishvi-rule);
  padding: 4px;
  text-align: left;
}

table.move-list thead th {
  color: var(--tishvi-grey-text);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.move-cell {
  width: 100%;
  min-height: var(--touch-target);
  background: none;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  text-align: left;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.move-cell:hover {
  background: var(--tishvi-green-lt);
}

.move-san {
  font-weight: 700;
}

.move-clock {
  font-size: 0.75rem;
  color: var(--tishvi-grey-text);
}

/* ---------- Clock panel ---------- */

.clock-panel {
  margin-bottom: 16px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  padding: 8px 12px;
}

.clock-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--tishvi-green);
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
}

.clock-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.clock-fields label {
  font-size: 0.9rem;
  color: var(--tishvi-grey-text);
}

.clock-fields input {
  min-height: var(--touch-target);
  padding: 0 10px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  width: 110px;
}

/* ---------- Promotion modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 30, 30, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.promotion-dialog {
  background: var(--tishvi-paper);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.promotion-choices {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.promotion-choice {
  width: 56px;
  height: 56px;
  font-size: 28px;
  border-radius: 8px;
  background: var(--tishvi-green-lt);
  border: 1px solid var(--tishvi-green);
}

/* ---------- Finish button ---------- */

.finish-btn {
  width: 100%;
  margin-top: 8px;
}

/* ---------- Game details form ---------- */

.game-details-screen,
.review-export-screen {
  max-width: 480px;
  margin: 0 auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.85rem;
  color: var(--tishvi-grey-text);
}

.field input {
  min-height: var(--touch-target);
  padding: 0 12px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 1rem;
  background: #fff;
  color: var(--tishvi-ink);
}

.result-fieldset {
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  padding: 10px 14px 14px;
  margin: 0 0 14px 0;
}

.result-fieldset legend {
  padding: 0 4px;
  font-size: 0.85rem;
  color: var(--tishvi-grey-text);
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--touch-target);
}

.form-error {
  color: #b22f25;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.game-details-screen form button[type='submit'] {
  width: 100%;
}

/* ---------- Review & export ---------- */

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0;
}

.export-actions button {
  width: 100%;
}

.copy-status {
  font-size: 0.85rem;
  color: var(--tishvi-green);
  text-align: center;
  min-height: 1.2em;
}

.pgn-preview {
  width: 100%;
  min-height: 160px;
  font-family: monospace;
  font-size: 0.85rem;
  padding: 10px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  margin-bottom: 16px;
}

/* ---------- How this works ---------- */

.how-it-works {
  max-width: 480px;
  margin: 0 auto 20px;
  border: 1px solid var(--tishvi-rule);
  border-radius: 8px;
  padding: 4px 14px;
}

.how-it-works summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--tishvi-green);
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
}

.how-it-works ul {
  margin: 0 0 12px 0;
  padding-left: 20px;
  color: var(--tishvi-grey-text);
  font-size: 0.9rem;
  line-height: 1.5;
}

.how-it-works li {
  margin-bottom: 8px;
}

/* ---------- Saved games list ---------- */

#saved-games-root {
  max-width: 480px;
  margin: 0 auto;
}

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

.saved-game-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--tishvi-rule);
}

.saved-game-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--tishvi-rule);
  flex-shrink: 0;
}

.saved-game-thumb-empty {
  background: var(--tishvi-diagram);
}

.saved-game-info {
  flex: 1;
  min-width: 0;
}

.saved-game-title {
  margin: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-game-meta {
  margin: 2px 0 0 0;
  font-size: 0.85rem;
  color: var(--tishvi-grey-text);
}

.saved-game-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.saved-game-actions button {
  min-height: var(--touch-target);
  padding: 0 12px;
  font-size: 0.85rem;
}

.delete-btn {
  color: #b22f25;
  border-color: #b22f25;
}
