:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef2f5;
  --line: #d5dde5;
  --line-strong: #aeb9c5;
  --text: #1f2933;
  --muted: #617083;
  --accent: #167a6b;
  --accent-strong: #0f5f55;
  --danger: #b54949;
  --ink: #1b1f24;
  --saved: #d9efe9;
  --pending: #f7f9fb;
  --shadow: 0 14px 34px rgba(25, 38, 52, 0.10);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button,
select,
input,
textarea,
.file-button {
  border: 1px solid var(--line);
  border-radius: 6px;
}

button,
.file-button {
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

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

button:hover:not(:disabled),
.file-button:hover {
  border-color: var(--line-strong);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(360px, 1fr) minmax(260px, 320px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

textarea,
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="text"],
input[type="url"],
[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

.panel {
  background: var(--surface);
  border-color: var(--line);
}

.queue-panel {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  position: sticky;
  top: 0;
}

.detail-panel {
  border-left: 1px solid var(--line);
  padding: 18px;
  display: grid;
  gap: 22px;
  align-content: start;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  position: sticky;
  top: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.3;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.app-version {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.update-link {
  display: grid;
  min-height: 38px;
  place-items: center;
  color: var(--text);
  text-decoration: none;
}

h2 {
  font-size: 15px;
  line-height: 1.4;
  margin-bottom: 10px;
}

.panel-header p,
.stats-line,
#currentMeta,
.detail-grid dt {
  color: var(--muted);
}

.panel-header p {
  margin-top: 4px;
  font-size: 12px;
}

.import-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  padding: 10px;
  line-height: 1.55;
  color: var(--text);
  background: #fbfcfd;
}

input,
select {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  background: #fbfcfd;
  color: var(--text);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.control-grid label,
.toggle-row label {
  font-size: 12px;
  color: var(--muted);
}

.control-grid label {
  display: grid;
  gap: 4px;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.toggle-row input {
  width: auto;
  min-height: auto;
  margin-right: 4px;
}

.button-row,
.tool-strip,
.button-column {
  display: flex;
  gap: 8px;
}

.button-row button,
.tool-strip button {
  flex: 1;
}

.button-column {
  flex-direction: column;
}

.font-fields {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.font-fields label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

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

.secondary-button {
  background: var(--surface-soft);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.queue-search {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.stats-line {
  white-space: nowrap;
  font-size: 13px;
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow: auto;
  min-height: 0;
  display: grid;
  gap: 4px;
  align-content: start;
}

.queue-item {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--pending);
  min-height: 44px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  cursor: pointer;
}

.queue-item:hover {
  border-color: var(--line);
}

.queue-item.active {
  border-color: var(--accent);
  background: #edf8f5;
}

.queue-item.recorded {
  background: var(--saved);
}

.queue-window-note {
  padding: 8px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.queue-char {
  font-size: 26px;
  line-height: 1;
  text-align: center;
}

.queue-meta {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.queue-meta strong,
.queue-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta strong {
  font-size: 13px;
}

.queue-meta span,
.queue-index {
  font-size: 12px;
  color: var(--muted);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  position: sticky;
  top: 0;
}

.glyph-toolbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  gap: 12px;
}

.current-glyph {
  text-align: center;
  display: grid;
  gap: 4px;
}

#currentChar {
  font-size: 40px;
  line-height: 1;
  font-weight: 700;
}

#currentMeta {
  font-size: 13px;
}

.canvas-band {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  touch-action: none;
  overscroll-behavior: contain;
}

.canvas-wrap {
  width: min(72vh, 100%);
  max-width: 720px;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

#recordCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}

.tool-strip {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.pen-mode-toggle {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--surface-soft);
  white-space: nowrap;
  font-size: 13px;
}

.pen-mode-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.progress-block,
.preview-block,
.export-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

#progressFill {
  width: 0;
  height: 100%;
  background: var(--accent);
}

.detail-grid {
  margin: 16px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-grid div {
  min-height: 52px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px;
  background: var(--surface-soft);
  border-radius: 6px;
}

.detail-grid dt,
.detail-grid dd {
  margin: 0;
}

.detail-grid dd {
  font-size: 20px;
  font-weight: 700;
}

#previewCanvas {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
}

#pathSummary {
  margin: 10px 0 0;
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
}

.input-debug-panel {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.input-debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.input-debug-header h2 {
  margin: 0;
}

.input-debug-header .button-row {
  grid-template-columns: repeat(2, minmax(64px, 1fr));
}

#inputDebugLog {
  max-height: 260px;
  margin: 10px 0 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--muted);
  font: 11px/1.45 Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}

.file-button {
  display: grid;
  place-items: center;
  background: var(--surface-soft);
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: #1f2933;
  color: #fff;
  min-width: 180px;
  max-width: min(90vw, 520px);
  padding: 10px 14px;
  border-radius: 6px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(280px, 340px) 1fr;
  }

  .detail-panel {
    grid-column: 1 / -1;
    height: auto;
    min-height: auto;
    position: static;
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-template-columns: repeat(3, 1fr);
  }

  .progress-block,
  .preview-block,
  .export-block {
    border-bottom: 0;
    padding-bottom: 0;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
  }

  .queue-panel,
  .workspace {
    height: auto;
    min-height: auto;
    position: static;
    overflow: visible;
  }

  .queue-list {
    max-height: 320px;
  }

  .canvas-band {
    padding: 14px;
  }

  .canvas-wrap {
    width: 100%;
  }

  .tool-strip {
    flex-wrap: wrap;
  }

  .tool-strip button {
    min-width: calc(50% - 4px);
  }

  .pen-mode-toggle {
    width: 100%;
  }

  .detail-panel {
    display: grid;
    grid-template-columns: 1fr;
  }
}
