:root {
  color-scheme: light;
  --bg: #eee9df;
  --panel: #fffaf0;
  --ink: #1f1a14;
  --muted: #6b6258;
  --line: #d8cdbc;
  --accent: #5a4634;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.site-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #f7f1e8;
}
h1 { margin: 0 0 4px; font-size: 22px; }
p { margin: 0; color: var(--muted); }
.status {
  min-width: 220px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  font-size: 13px;
  color: var(--muted);
}
.layout {
  display: grid;
  grid-template-columns: minmax(330px, 420px) 1fr;
  gap: 18px;
  padding: 18px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,.06);
}
.input-panel { padding: 16px; }
.label { display: block; font-weight: 700; margin-bottom: 8px; }
textarea {
  width: 100%;
  height: 220px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  font-size: 16px;
  line-height: 1.6;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-top: 14px;
}
.controls label,
.checkboxes label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.controls input[type="number"] {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}
.controls input[type="range"] { width: 100%; }
.checkboxes {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}
.checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: .45; cursor: wait; }
.details { margin-top: 14px; color: var(--muted); }
pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}
.canvas-panel { padding: 12px; min-height: 70vh; }
.canvas-wrap {
  overflow: auto;
  height: calc(100vh - 170px);
  min-height: 520px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 18% 18%, rgba(90,70,52,.05), transparent 18%),
    linear-gradient(135deg, rgba(255,255,255,.45), rgba(0,0,0,.03)),
    #e7dccb;
  border: 1px solid var(--line);
  padding: 16px;
}
canvas {
  display: block;
  background: #fbf6ea;
  box-shadow: 0 8px 18px rgba(0,0,0,.15);
}
.credit {
  padding: 14px 22px 24px;
  color: var(--muted);
  font-size: 12px;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .canvas-wrap { height: auto; min-height: 360px; }
  .site-header { flex-direction: column; }
}


select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.canvas-wrap canvas { cursor: pointer; }

.glyph-picker.hidden { display: none; }
.glyph-picker { position: fixed; inset: 0; z-index: 2000; }
.glyph-picker-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.28); }
.glyph-picker-panel {
  position: relative;
  margin: 4vh auto;
  width: min(920px, calc(100vw - 24px));
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 44px rgba(0,0,0,.28);
  padding: 14px;
}
.glyph-picker-header { display:flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.glyph-picker-header h2 { margin: 0 0 4px; font-size: 18px; }
.glyph-picker-header p { margin: 0; font-size: 13px; }
.glyph-picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; margin-top: 8px; }
.glyph-choice {
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 10px;
  padding: 5px;
  color: var(--ink);
  display: grid;
  gap: 4px;
  align-items: start;
}
.glyph-choice.active { outline: 2px solid #8b6847; }
.glyph-choice .thumb {
  height: 58px;
  display:flex; align-items:center; justify-content:center;
  background: #f5ede0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.glyph-choice .thumb img { max-width: 100%; max-height: 100%; display:block; }
.glyph-choice .thumb.fallback-sample { font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: 28px; color: #211810; }
.glyph-choice .caption { font-size: 9px; line-height: 1.25; color: var(--muted); word-break: break-word; }
.ghost-btn { background: #ece2d2; color: var(--accent); }
.tap-help { font-size: 12px; color: var(--muted); margin-top: 8px; }


/* Tokyo Kaii Sosa-roku links */
.top-link-buttons {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1300;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid rgba(90, 70, 52, 0.34);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(3px);
}

.top-link-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: #efe5d4;
  color: var(--accent);
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1;
  text-decoration: none;
  box-sizing: border-box;
}

.top-link-buttons a:hover {
  background: var(--accent);
  color: #fff;
}

.site-header {
  padding-right: 168px;
}

.project-credit {
  margin-bottom: 4px;
  color: var(--ink);
  font-weight: 700;
}

.project-links {
  margin-bottom: 10px;
}

.dataset-credit {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.credit a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(90, 70, 52, 0.38);
}

.credit a:hover {
  border-bottom-color: var(--accent);
}

@media (max-width: 900px) {
  .site-header {
    padding-right: 150px;
  }
}

@media (max-width: 520px) {
  .top-link-buttons {
    top: 8px;
    right: 8px;
    gap: 6px;
    padding: 5px 7px;
  }

  .top-link-buttons a {
    width: 30px;
    height: 30px;
    font-size: 0.88rem;
  }

  .site-header {
    padding-right: 138px;
  }
}

/* Per-glyph finishing controls */
.glyph-adjuster {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f0e4;
}

.glyph-adjuster-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.glyph-adjuster-title-row h3 {
  margin: 0;
  font-size: 15px;
  color: var(--ink);
}

.compact-btn {
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.glyph-adjustment-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.glyph-adjustment-row {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.adjustment-control-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  gap: 7px;
  align-items: center;
}

.adjustment-control-row input[type="range"] {
  width: 100%;
  min-width: 0;
  margin: 0;
}

.adjust-step-btn {
  min-height: 36px;
  padding: 5px;
  border: 1px solid #cbb89e;
  border-radius: 9px;
  background: #e7dac6;
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
}

.adjust-step-btn:active {
  transform: translateY(1px);
  background: #d8c5a8;
}

.adjustment-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.adjustment-label-row output {
  color: var(--accent);
  font-weight: 800;
  white-space: nowrap;
}

.adjustment-help {
  font-size: 10px;
  line-height: 1.3;
}

.glyph-adjustment-note {
  margin: 9px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.glyph-candidates-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf0;
  overflow: hidden;
}

.glyph-candidates-summary {
  list-style: none;
  cursor: pointer;
  min-height: 52px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  user-select: none;
}

.glyph-candidates-summary::-webkit-details-marker { display: none; }

.glyph-candidates-summary-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.glyph-candidates-chevron {
  display: inline-block;
  transition: transform .15s ease;
  color: var(--accent);
}

.glyph-candidates-details[open] .glyph-candidates-chevron {
  transform: rotate(90deg);
}

.glyph-candidate-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.glyph-current-preview {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5ede0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 24px;
  color: #211810;
}

.glyph-current-preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.glyph-candidates-details .glyph-picker-list {
  padding: 0 8px 8px;
}

@media (max-width: 640px) {
  .glyph-picker-panel {
    margin: 2vh auto;
    max-height: 96vh;
  }

  .glyph-adjustment-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .adjustment-control-row {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }
}

