:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --field-bg: #ffffff;
  --ink: #14213d;
  --muted: #64748b;
  --line: #dbe3ee;
  --brand: #1666d9;
  --brand-strong: #0d3f8f;
  --teal: #0f9f9a;
  --gold: #d99a1e;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  font-family: "Be Vietnam Pro", "Inter", Arial, sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #101b2d;
  --surface-soft: #14243a;
  --panel-bg: rgba(16, 27, 45, 0.94);
  --field-bg: #0d1a2b;
  --ink: #edf5ff;
  --muted: #a8b7cc;
  --line: #29405c;
  --brand: #5aa2ff;
  --brand-strong: #9cc8ff;
  --teal: #2dd4bf;
  --gold: #f8c84c;
  --danger: #fca5a5;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(244, 247, 251, 0.96) 38%, #eef4f7 100%),
    var(--bg);
}

body[data-theme="dark"] {
  background:
    linear-gradient(180deg, rgba(7, 17, 31, 0.98), rgba(9, 18, 32, 0.98) 42%, #08131f 100%),
    var(--bg);
}

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

button {
  border: 0;
}

img,
canvas {
  display: block;
  max-width: 100%;
}

.site-header {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 44px) 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.header-copy {
  max-width: 820px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(30px, 4.8vw, 58px);
  line-height: 1.04;
  letter-spacing: 0;
}

.header-copy p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(15px, 1.7vw, 19px);
  line-height: 1.7;
}

.header-actions {
  display: flex;
  align-items: stretch;
  gap: 12px;
}

.language-switch,
.theme-toggle,
.author-box {
  border: 1px solid var(--line);
  background: var(--panel-bg);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  border-radius: var(--radius);
}

.language-switch {
  display: flex;
  padding: 4px;
  gap: 4px;
  height: 46px;
}

.lang-btn {
  min-width: 44px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

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

.theme-toggle {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.theme-toggle span {
  min-width: 48px;
  padding: 10px 12px;
  border-radius: 6px;
  text-align: center;
}

body:not([data-theme="dark"]) .theme-toggle span:first-child,
body[data-theme="dark"] .theme-toggle span:last-child {
  color: #fff;
  background: var(--brand);
}

.author-box {
  min-width: 190px;
  padding: 10px 14px;
}

.author-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.author-box strong {
  display: block;
  margin-top: 2px;
  color: var(--brand-strong);
  font-size: 14px;
}

.app-shell {
  max-width: 1640px;
  margin: 0 auto;
  padding: 12px clamp(16px, 4vw, 44px) 34px;
  display: grid;
  grid-template-columns: minmax(360px, 560px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.controls,
.preview-area {
  min-width: 0;
}

.controls {
  display: grid;
  gap: 14px;
}

.control-section,
.preview-area,
.guide {
  border: 1px solid var(--line);
  background: var(--panel-bg);
  border-radius: var(--radius);
  box-shadow: 0 14px 42px rgba(15, 23, 42, 0.08);
}

.control-section {
  min-width: 0;
  overflow: hidden;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.section-heading > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-heading span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: #e8f1ff;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.split-heading {
  justify-content: space-between;
}

.field {
  min-width: 0;
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.compact-field {
  margin-bottom: 12px;
}

.field > span,
.field label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  color: var(--ink);
  background: var(--field-bg);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  border-color: rgba(22, 102, 217, 0.7);
  box-shadow: 0 0 0 4px rgba(22, 102, 217, 0.12);
}

.input-grid,
.upload-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.color-field input[type="color"] {
  width: 100%;
  height: 48px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
}

.upload-box {
  min-width: 0;
  min-height: 88px;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px dashed #b7c5d8;
  border-radius: var(--radius);
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
}

.upload-box:hover {
  border-color: var(--brand);
  background: #eef6ff;
  transform: translateY(-1px);
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-thumb {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 6px;
  background: #dfeafe;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  background-size: cover;
  background-position: center;
}

.upload-box strong,
.upload-box small {
  display: block;
}

.upload-box strong {
  color: var(--ink);
  font-size: 14px;
}

.upload-box small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
  font-size: 12px;
}

.form-error {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.template-select-grid {
  align-items: end;
}

.template-summary {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.template-summary-preview {
  min-height: 74px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.template-summary strong,
.template-summary div > span,
.template-summary p {
  display: block;
}

.template-summary strong {
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
}

.template-summary div > span {
  width: fit-content;
  margin-bottom: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: rgba(22, 102, 217, 0.12);
  font-size: 11px;
  font-weight: 900;
}

.template-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.fixed-size-note {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.fixed-size-note span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.fixed-size-note strong {
  color: var(--brand-strong);
  font-size: 18px;
}

.fixed-size-note small {
  grid-column: 1 / -1;
  color: var(--muted);
  line-height: 1.45;
}

.category-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 10px;
  scrollbar-width: thin;
}

.category-btn {
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef3f8;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.category-btn.is-active {
  color: var(--brand-strong);
  background: #e8f1ff;
  border-color: #b6d2ff;
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 550px;
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}

.template-card {
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 12px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}

.template-card:hover,
.template-card.is-selected {
  border-color: var(--brand);
  box-shadow: 0 12px 30px rgba(22, 102, 217, 0.12);
  transform: translateY(-1px);
}

.template-preview {
  position: relative;
  min-height: 72px;
  overflow: hidden;
  border-radius: 6px;
  background: #14213d;
}

.template-preview::before,
.template-preview::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.template-preview::before {
  width: 34px;
  height: 34px;
  left: 12px;
  top: 20px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.2);
}

.template-preview::after {
  width: 42px;
  height: 8px;
  right: 12px;
  top: 26px;
  box-shadow: 0 14px 0 rgba(255, 255, 255, 0.72), 0 28px 0 rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.92);
}

.template-info {
  min-width: 0;
}

.template-info h3 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.template-info p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.template-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: #e8f1ff;
  font-size: 11px;
  font-weight: 900;
}

.selected-label {
  display: none;
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
}

.template-card.is-selected .selected-label {
  display: inline;
}

.switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.switch {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.18s;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.22);
  transition: transform 0.18s;
}

.switch input:checked + span {
  background: var(--teal);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.switch b {
  color: var(--ink);
  font-size: 13px;
}

.action-row {
  position: static;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-bg);
  box-shadow: 0 14px 42px rgba(15, 23, 42, 0.08);
}

.btn {
  min-width: 0;
  min-height: 46px;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 0.18s, filter 0.18s, box-shadow 0.18s;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.btn:focus-visible,
.lang-btn:focus-visible,
.theme-toggle:focus-visible,
.category-btn:focus-visible,
.template-card:focus-visible {
  outline: 3px solid rgba(22, 102, 217, 0.28);
  outline-offset: 2px;
}

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

.btn.secondary {
  color: #102a43;
  background: #f3c969;
}

.btn.ghost {
  grid-column: 1 / -1;
  color: var(--brand-strong);
  background: rgba(22, 102, 217, 0.12);
}

.preview-area {
  position: sticky;
  top: 16px;
  padding: 18px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.preview-toolbar h2 {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
}

.size-pill {
  flex: 0 0 auto;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: #e8f1ff;
  border: 1px solid #c5dcff;
  font-size: 12px;
  font-weight: 900;
}

.canvas-stage {
  overflow: hidden;
  border: 1px solid #0f172a;
  border-radius: var(--radius);
  background: #0f172a;
  box-shadow: var(--shadow);
}

#honorCanvas {
  width: 100%;
  height: auto;
}

.guide {
  margin-top: 16px;
  padding: 16px 18px;
  box-shadow: none;
}

.guide h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

.guide ol {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.7;
}

.site-footer {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 44px) 34px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .preview-area {
    position: static;
  }
}

@media (max-width: 760px) {
  .site-header {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .author-box {
    flex: 1 1 180px;
  }

  .language-switch,
  .theme-toggle {
    flex: 0 0 auto;
  }

  .input-grid,
  .upload-grid,
  .color-grid,
  .switch-grid,
  .action-row {
    grid-template-columns: 1fr;
  }

  .template-grid {
    max-height: none;
    grid-template-columns: 1fr;
  }

  .template-card {
    grid-template-columns: 86px 1fr;
  }

  .template-summary {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .btn.ghost {
    grid-column: auto;
  }
}

@media (max-width: 430px) {
  .control-section,
  .preview-area,
  .guide {
    padding: 14px;
  }

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

  .template-preview {
    min-height: 96px;
  }
}
