/* Card studio · 字词学习 — LingoFruit Chinese
 * Module-specific styles layered over /tokens.css and /site.css. */

/* ---- Studio header & quiet mode tabs ---- */
.studio-head {
  padding: clamp(28px, 4.5vw, 52px) 0 0;
}

.hub-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 12px;
  row-gap: 4px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-h1);
  line-height: 1.08;
  letter-spacing: -0.03em;
  margin: var(--s-2) 0 var(--s-3);
  color: var(--ink);
}

.hub-title .title-zh {
  font-family: var(--font-zh);
  font-size: 0.54em;
  color: var(--accent-mid);
  font-weight: 500;
  white-space: nowrap;
}

.studio-head .lead {
  max-width: 60ch;
  margin: 0 0 var(--s-5);
}

.hubTabs {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--rule);
}

.hub-tab {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 2px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--ink-3);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.hub-tab:hover {
  color: var(--ink);
  border-bottom-color: var(--rule-strong);
}

.hub-tab[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 650;
}

/* ---- Primary actions row (Word cards pane) ---- */
.studio-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-5) 0 var(--s-4);
}

/* ---- Character explorer pane (#characters) ---- */
#charPane {
  padding: var(--s-5) 0 var(--s-7);
}

.char-panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: clamp(18px, 3.5vw, 32px);
  box-shadow: var(--shadow-sm);
}

.char-controls {
  margin-bottom: var(--s-4);
}

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: var(--s-2);
}

#hanQuery {
  display: block;
  width: min(100%, 420px);
  margin-bottom: var(--s-3);
}

#hanGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: var(--s-3);
  margin: var(--s-4) 0 var(--s-5);
}

#hanGrid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 132px;
  padding: var(--s-4) var(--s-2);
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--r-md);
  cursor: pointer;
  min-width: 0;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}

#hanGrid button .han-glyph {
  font-family: var(--font-zh);
  font-size: clamp(38px, 4vw, 58px);
  line-height: 1.15;
  color: var(--ink);
}

#hanGrid button .han-py {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ochre);
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#hanGrid button:hover {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

#hanGrid button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---- Toolbar ---- */
.toolbar {
  border-top: 1px solid var(--rule);
  padding: var(--s-5) 0 var(--s-3);
  display: grid;
  gap: var(--s-4);
}

.searchbar {
  position: relative;
  max-width: 460px;
}

.searchbar input {
  width: 100%;
  padding-right: 46px;
}

.searchbar button {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  cursor: pointer;
  color: var(--ink-3);
}

.searchbar button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.levels {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.level {
  min-height: 44px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink-2);
  padding: 0 16px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.level:hover {
  border-color: var(--accent-mid);
  color: var(--ink);
}

.level[aria-selected="true"] {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.count {
  color: var(--ink-3);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.toolrow {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  padding: var(--s-3) 0 var(--s-5);
}

/* ---- Card grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--s-4);
  padding-bottom: var(--s-6);
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--s-5) var(--s-4) var(--s-4);
  cursor: pointer;
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card:hover {
  border-color: var(--accent-mid);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card .lv {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  color: var(--ochre);
  border: 1px solid var(--ochre-rule);
  background: var(--ochre-soft);
  padding: 2px 7px;
  border-radius: var(--r-sm);
}

.card .del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--err);
  cursor: pointer;
  border-radius: var(--r-sm);
  display: none;
  align-items: center;
  justify-content: center;
}

.card.custom .del {
  display: inline-flex;
}

.card .del:hover {
  background: var(--err-bg);
}

.card .hz {
  margin: var(--s-5) auto var(--s-2);
  font-family: var(--font-zh);
  font-size: 36px;
  line-height: 1.25;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.card .py {
  color: var(--ochre);
  font-weight: 600;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.card .en {
  color: var(--ink-2);
  font-size: var(--text-base);
  margin-top: 4px;
}

.card .ex {
  color: var(--ink-3);
  font-size: 13px;
  margin-top: var(--s-3);
  padding-top: var(--s-2);
  border-top: 1px solid var(--rule-soft);
  width: 100%;
  font-family: var(--font-zh);
}

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: var(--s-7) 0;
  line-height: 1.8;
}

/* ---- Scene import preview ---- */
.import {
  background: var(--accent-soft);
  border: 1px solid var(--accent-rule);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin: 0 0 var(--s-6);
  box-shadow: var(--shadow-sm);
}

.import-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}

.import-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-h3);
}

.import-summary {
  color: var(--ink-2);
  font-size: var(--text-sm);
  margin: var(--s-2) 0 var(--s-4);
}

.import-list {
  list-style: none;
  margin: 0 0 var(--s-4);
  padding: 0;
  display: grid;
  gap: var(--s-2);
  max-height: 430px;
  overflow: auto;
}

.import-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px var(--s-4);
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  position: relative;
}

.import-item.dup { opacity: 0.6; }
.import-item.empty-item { display: block; color: var(--ink-3); font-size: var(--text-sm); }
.imp-hanzi { font-family: var(--font-zh); font-size: 26px; line-height: 1.25; }
.imp-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-right: 92px; }
.imp-pinyin { color: var(--ochre); font-weight: 600; font-size: var(--text-sm); }
.imp-meaning { color: var(--ink-2); font-size: var(--text-sm); }
.imp-ex { color: var(--ink-3); font-size: 13px; }
.imp-ex::before { content: "例句 · "; color: var(--ink-4); }

.imp-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--r-sm);
}

.imp-badge.new { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-rule); }
.imp-badge.dup { background: var(--ochre-soft); color: var(--ochre); border: 1px solid var(--ochre-rule); }
.import-actions { display: flex; gap: var(--s-3); flex-wrap: wrap; }

/* ---- Builder form ---- */
.builder {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: clamp(20px, 4vw, 32px);
  margin: 0 0 var(--s-7);
  box-shadow: var(--shadow-sm);
}

.builder h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-h3);
  margin: 0 0 var(--s-2);
}

.hint {
  color: var(--ink-3);
  font-size: var(--text-sm);
  margin: 0 0 var(--s-5);
}

#cardForm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-2);
}

.req { color: var(--err); }
.form-actions { grid-column: 1 / -1; display: flex; gap: var(--s-3); flex-wrap: wrap; padding-top: var(--s-2); }

/* ---- Study overlay ---- */
.study {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(19, 46, 38, 0.78);
  display: grid;
  place-items: center;
  padding: var(--s-3);
  backdrop-filter: blur(4px);
}

.study-inner {
  position: relative;
  width: min(100%, 540px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.study-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  color: var(--ink-3);
  border-radius: var(--r-sm);
}

.study-close:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.study-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-right: 48px;
  min-height: 44px;
  margin-bottom: var(--s-3);
}

.hidepin {
  font-size: var(--text-sm);
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 44px;
}

.flash {
  width: 100%;
  min-height: 148px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  display: block;
  font-family: inherit;
  color: inherit;
  padding: 0;
  box-shadow: var(--shadow-sm);
}

.flash-front,
.flash-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--s-5) var(--s-4);
  min-height: 148px;
  border-radius: var(--r-md);
}

.flash-back,
.flash.flipped .flash-front {
  display: none;
}

.flash.flipped .flash-back {
  display: flex;
  background: var(--surface-2);
}

.flash-han {
  font-family: var(--font-zh);
  font-size: clamp(2.25rem, 8vw, 3.25rem);
  line-height: 1.2;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.flash-pinyin {
  color: var(--ochre);
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.flash-level {
  color: var(--ink-3);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.flash-en {
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: var(--ink);
}

.flash-ex {
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 40ch;
}

.flash-ex b {
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: 1.0625rem;
  font-weight: 500;
  display: block;
  margin-bottom: 4px;
}

/* ---- Stroke order & handwriting box ---- */
#inkBox {
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid var(--rule);
}

.inkHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}

.inkHead strong {
  font-size: var(--text-sm);
  color: var(--ink);
}

.inkHead small {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-left: 6px;
}

#inkTabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#inkTabs button {
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: 20px;
  cursor: pointer;
}

#inkTabs button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}

#inkStage {
  width: 154px;
  height: 154px;
  margin: var(--s-2) auto;
  border: 1px solid var(--gridline);
  border-radius: var(--r-sm);
  background:
    linear-gradient(45deg, transparent 49.6%, rgba(216, 204, 184, 0.55) 50%, transparent 50.4%),
    linear-gradient(-45deg, transparent 49.6%, rgba(216, 204, 184, 0.55) 50%, transparent 50.4%),
    linear-gradient(90deg, transparent 49.5%, var(--gridline) 50%, transparent 50.5%),
    linear-gradient(transparent 49.5%, var(--gridline) 50%, transparent 50.5%),
    var(--surface);
}

#inkMeta,
#variants,
#traceStatus {
  font-size: var(--text-sm);
  color: var(--ink-3);
  margin: var(--s-2) 0;
}

.ink-trace-row {
  display: flex;
  justify-content: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin: var(--s-3) 0;
}

#pad {
  touch-action: none;
  width: 212px;
  height: 212px;
  margin: var(--s-3) auto;
  border: 1px solid var(--gridline);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.inkActions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-top: var(--s-3);
}

.inkActions button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.inkActions button:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent-mid);
}

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

.flash-hint {
  color: var(--ink-3);
  font-size: var(--text-xs);
  margin: var(--s-4) 0 var(--s-2);
}

.study-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--s-2);
  margin-top: var(--s-2);
}

.study-nav .btn {
  padding-inline: 10px;
}

/* ---- Print ---- */
#printArea { display: none; }

@media (max-width: 900px) {
  #hanGrid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--s-3);
  }

  .card {
    padding: var(--s-4) var(--s-3) var(--s-3);
  }

  .card .hz {
    font-size: 30px;
  }

  .study-inner {
    padding: var(--s-4);
  }
}

@media (max-width: 520px) {
  #hanGrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--s-2);
  }

  #hanGrid button {
    min-height: 92px;
    padding: var(--s-3) var(--s-1);
  }
}

@media print {
  .studio-head, .studio-actions, #charPane, .toolbar, .toolrow, .grid, .builder, .study, .empty, .import, .ref-banner, .related-strip {
    display: none !important;
  }
  #cardsPane { display: block !important; }
  #printArea { display: block !important; width: 100%; }
  .psheet-head { text-align: center; margin-bottom: 12px; break-after: avoid; page-break-after: avoid; }
  .psheet-head h1 { font-size: 18px; margin: 0; color: #000; }
  .psheet-head p { font-size: 11px; color: #333; margin: 4px 0; }
  .psheet-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: stretch;
  }
  .pcard {
    width: calc(50% - 5px);
    box-sizing: border-box;
    border: 1.5px solid #000;
    border-radius: 6px;
    break-inside: avoid;
    page-break-inside: avoid;
    background: #fff;
    color: #000;
  }
  .pcard-front { padding: 10px 8px 8px; text-align: center; }
  .pcard-han { font-family: var(--font-zh); font-size: 40px; line-height: 1.15; margin: 2px 0; }
  .pcard-pinyin { font-size: 14px; color: #000; font-weight: 700; }
  .pcard-fold {
    border-top: 1.5px dashed #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 8px;
    font-size: 9px;
    color: #555;
  }
  .pcard-back { padding: 8px 10px 10px; text-align: center; border-top: 1px solid #ccc; }
  .pcard-en { font-size: 15px; font-weight: 700; }
  .pcard-ex { font-size: 11px; color: #333; margin-top: 4px; line-height: 1.4; }
  .pcard-level { font-size: 10px; color: #444; margin-top: 3px; }
  @page { margin: 12mm; }
}
