/* ── Variables ── */
:root {
  --box-size: 1.3cm;
  --border: 1.5px solid #111;
  --row-gap: 0.5cm;
}

/* ── Reset / base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, sans-serif;
  font-size: 14px;
  display: flex;
  gap: 2rem;
  padding: 1.5rem;
  background: #f5f5f5;
  min-height: 100vh;
}

/* ── Controls panel ── */
.controls {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  align-self: flex-start;
  position: sticky;
  top: 1.5rem;
}

.lang-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: .5rem;
}

.lang-row select {
  width: auto;
  font-size: .8rem;
  padding: .2rem .35rem;
}

.controls h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: #333;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: .75rem;
}

.form-grid label {
  min-width: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .8rem;
  color: #555;
  font-weight: 500;
}

label.full-width { margin-bottom: .75rem; }

.trace-row {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  margin-bottom: .75rem;
  cursor: pointer;
  font-size: .85rem;
  color: #444;
  font-weight: 400;
}

.trace-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: #2563eb;
  cursor: pointer;
}

input[type="text"],
input[type="number"],
select,
textarea {
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: .35rem .5rem;
  font-size: .85rem;
  font-family: inherit;
  color: #222;
  background: #fafafa;
  width: 100%;
}

input[type="number"] { max-width: 80px; }

.words-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.words-actions {
  display: flex;
  gap: .25rem;
  flex-shrink: 0;
}

.words-actions button {
  font-size: .7rem;
  padding: .15rem .45rem;
  background: none;
  color: #555;
  border: 1px solid #ccc;
  border-radius: 3px;
}

.words-actions button:hover {
  background: #f0f0f0;
  border-color: #aaa;
  color: #222;
}

textarea { resize: vertical; font-size: .9rem; line-height: 1.5; }

.hint { font-weight: 400; color: #888; }

.buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .25rem; }

.version-row { margin-top: auto; padding-top: .75rem; text-align: center; }
.version-row a { font-size: .75rem; color: #aaa; text-decoration: none; }
.version-row a:hover { color: #555; }

button {
  padding: .45rem 1rem;
  border: none;
  border-radius: 4px;
  font-size: .85rem;
  cursor: pointer;
  font-family: inherit;
  background: #2563eb;
  color: #fff;
}

button:hover { background: #1d4ed8; }
button.secondary { background: #6b7280; }
button.secondary:hover { background: #4b5563; }

/* ── Sheet area ── */
main#sheet {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

/* ── Sheet page ── */
.sheet-page {
  background: #fff;
  padding: 1.5cm;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  max-width: 29.7cm;
  min-width: fit-content;
}

.sheet-page h1 {
  text-align: center;
  font-size: 1.4rem;
  margin-bottom: .4cm;
}

.sheet-page .instruction {
  text-align: center;
  font-size: .9rem;
  margin-bottom: .6cm;
  color: #333;
}

/* ── Cover page ── */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 16cm;
  justify-content: center;
  border-bottom: 2px dashed #ccc;
  margin-bottom: 2rem;
  padding-bottom: 2rem;
}

.cover-subtitle {
  font-size: 1rem;
  color: #666;
  margin-bottom: 1.2cm;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.cover-word-list {
  columns: 2;
  column-gap: 3cm;
  list-style-position: inside;
  padding: 0;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 2.2;
}

@media print {
  .cover-page {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
    page-break-after: always;
    min-height: auto;
    justify-content: flex-start;
    padding-top: 3cm;
  }
}

/* ── Main table ── */
.sheet-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid #333;
  padding: var(--row-gap) .4cm;
  vertical-align: middle;
  text-align: center;
}

.sheet-table thead th {
  background: #ebebeb;
  font-size: .85rem;
  font-weight: 600;
  padding: .3cm .4cm;
}

.word-col { text-align: left; white-space: nowrap; }
.word-cell { text-align: left; white-space: nowrap; }
.number-col, .number-cell { text-align: center; width: 1%; }

/* ── Letter strip (crossword style) ── */
.letter-strip {
  display: inline-flex;
}

.letter-box {
  width: var(--box-size);
  height: var(--box-size);
  border: var(--border);
  border-right: none;
  flex-shrink: 0;
}

.letter-box:last-child {
  border-right: var(--border);
}

/* Trace letters */
.letter-box, .letter-line {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trace-letter {
  font-family: 'Patrick Hand', cursive;
  color: #c8c8c8;
  font-size: calc(var(--box-size) * 0.72);
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.letter-line .trace-letter {
  align-self: flex-end;
  margin-bottom: 2px;
}

/* Bare letters style */
.letter-strip.bare {
  gap: 0;
}

.letter-bare {
  width: auto;
  min-width: calc(var(--box-size) * 0.55);
  height: var(--box-size);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Underscore / line style */
.letter-strip.lines {
  gap: 0.2cm;
}

.letter-line {
  width: var(--box-size);
  height: var(--box-size);
  border-bottom: 2px solid #111;
  flex-shrink: 0;
}

/* ── Print ── */
/* ── Mobile layout ── */
@media (max-width: 680px) {
  body {
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
  }

  .controls {
    width: 100%;
    position: static;
  }

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

  main#sheet {
    overflow-x: auto;
    width: 100%;
  }

  .sheet-page {
    min-width: fit-content;
  }
}

@media (max-width: 400px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Print ── */
@media print {
  .no-print { display: none !important; }

  @page { size: A4 landscape; margin: 1.5cm; }

  body {
    background: none;
    padding: 0;
    display: block;
  }

  main#sheet { all: unset; }

  .sheet-page {
    box-shadow: none;
    padding: 0;
    max-width: none;
  }

  .sheet-table thead { display: table-header-group; }
  .sheet-table tbody tr { page-break-inside: avoid; }
}
