*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #2b2b2b;
  --sidebar:    #383838;
  --panel:      #424242;
  --border:     #555;
  --text:       #ddd;
  --text-sub:   #888;
  --accent:     #5a9fd4;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */

#sidebar {
  width: 238px;
  flex-shrink: 0;
  background: var(--sidebar);
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section { }

fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px 8px;
}

legend {
  font-size: 11px;
  color: var(--text-sub);
  padding: 0 4px;
}

/* Load button */
.btn-load {
  display: block;
  text-align: center;
  padding: 9px;
  background: #505050;
  border: 1px dashed #666;
  border-radius: 4px;
  cursor: pointer;
  color: #ccc;
  font-size: 13px;
  transition: background 0.1s;
}
.btn-load:hover { background: #5a5a5a; }
input[type="file"] { display: none; }

.sub-hint {
  font-size: 10px;
  color: var(--text-sub);
  text-align: center;
  margin-top: 3px;
}

/* Navigation */
.nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.nav-row button {
  background: #505050;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}
.nav-row button:hover { background: #626262; }

#nav-counter { min-width: 52px; text-align: center; }

.nav-name {
  font-size: 10px;
  color: var(--text-sub);
  text-align: center;
  word-break: break-all;
  line-height: 1.4;
}

/* Form rows */
.field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}

.field-row label {
  width: 20px;
  font-size: 12px;
  color: var(--text-sub);
  flex-shrink: 0;
}

.suffix-row label { width: 42px; }

.field-row input[type="number"],
.field-row input[type="text"] {
  flex: 1;
  background: #4a4a4a;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 12px;
  min-width: 0;
}
.field-row input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

/* Modifier hints */
.mod-hint {
  font-size: 10px;
  color: #6a6a6a;
  line-height: 1.8;
  padding: 0 2px;
}

/* Generic block button */
.btn-block {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 3px;
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: filter 0.1s;
}
.btn-block:hover { filter: brightness(1.12); }
.btn-block:last-child { margin-bottom: 0; }

/* Undo */
#btn-undo {
  background: #545454;
  color: var(--text);
  border: 1px solid #666;
}

/* Alignment */
.btn-align {
  display: block;
  width: 100%;
  padding: 5px 8px;
  background: #4a7fb0;
  border: none;
  color: #fff;
  border-radius: 3px;
  margin-top: 5px;
  text-align: left;
  font-size: 12px;
  cursor: pointer;
  transition: filter 0.1s;
}
.btn-align:first-of-type { margin-top: 4px; }
.btn-align:hover { filter: brightness(1.15); }

.btn-match-all { background: #3a6fa0; }

.align-desc {
  font-size: 10px;
  color: #6a6a6a;
  margin-top: 7px;
  line-height: 1.65;
}

/* All Figs / Save */
.btn-allfigs { background: #c8b84a; color: #222; }
.btn-save    { background: #5cb85c; color: #fff; margin-bottom: 0; }

/* App name + version: the same look in every yukmmz.github.io app.
   The name takes the first row; the version sits under it on the left and
   ⛶, FB, ?, ⚙ on the right — the icons do not fit beside the name in 238px. */
.sidebar-head {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 2px 0 4px 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-right: -4px;   /* let the icons use part of the sidebar padding */
}

.head-icons {
  display: flex;
  align-items: center;
  gap: 2px;
}

.app-title {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  letter-spacing: .02em;
  line-height: 1.2;
  white-space: nowrap;
}

.app-version {
  font-size: 11px;
  font-weight: 400;
  opacity: .55;
  white-space: nowrap;
  cursor: pointer;
}
.app-version:hover { text-decoration: underline; }

/* ── QR overlay ─────────────────────────────────────────────────────────────── */

#qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
}
#qr-overlay[hidden] { display: none; }

#qr-card {
  background: #fff;
  color: #111;
  border-radius: 14px;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

#qr-row {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.qr-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.qr-label {
  font-size: 14px;
  font-weight: 700;
  color: #222;
}

.qr-img {
  width: min(36vmin, 260px);
  height: auto;
  image-rendering: pixelated;
  border: 1px solid #ddd;
}

.qr-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}
.qr-link:hover .qr-img { opacity: 0.82; }
.qr-link:hover .qr-url { text-decoration: underline; color: #0066cc; }

.qr-url {
  font-size: 11px;
  color: #555;
  text-align: center;
  max-width: 220px;
  word-break: break-all;
}

#qr-close {
  background: #2b2b2b;
  color: #eee;
  border: none;
  border-radius: 6px;
  padding: 8px 28px;
  font-size: 13px;
  cursor: pointer;
}
#qr-close:hover { background: #444; }

/* ── JSON section ────────────────────────────────────────────────────────────── */

#btn-export-json { background: #4a6a8a; color: #dde; }
#btn-import-json { background: #3a5a6a; color: #dde; }

/* ── Canvas ─────────────────────────────────────────────────────────────────── */

#canvas-wrap {
  flex: 1;
  position: relative;
  background: #484848;
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#drop-veil {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(80, 160, 255, 0.15);
  border: 3px dashed #5af;
  color: #7cf;
  font-size: 22px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  letter-spacing: 0.04em;
}
#drop-veil.active { display: flex; }

#toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.82);
  color: #eee;
  padding: 7px 20px;
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 100;
}
#toast.show { opacity: 1; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */

#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modal-box {
  background: var(--sidebar);
  border-radius: 8px;
  width: min(96vw, 1600px);
  height: 93vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 48px rgba(0, 0, 0, 0.55);
}

#modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #444;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: #ccc;
  flex-shrink: 0;
}

#modal-close {
  background: none;
  border: none;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 1px 7px 3px;
  border-radius: 3px;
  line-height: 1;
}
#modal-close:hover { background: #555; color: #fff; }

#modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.thumb-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 5px;
  padding: 4px;
  transition: border-color 0.12s, background 0.12s;
}
.thumb-cell:hover {
  border-color: #5af;
  background: rgba(80, 160, 255, 0.08);
}
.thumb-cell.active {
  border-color: #fa0;
  background: rgba(255, 170, 0, 0.10);
}
.thumb-cell canvas { display: block; border-radius: 2px; }

.thumb-name {
  font-size: 9px;
  color: var(--text-sub);
  margin-top: 4px;
  max-width: 144px;
  text-align: center;
  word-break: break-all;
  line-height: 1.35;
}

/* ── Common header / settings pieces (same in every yukmmz.github.io app) ──── */

:root {
  --muted:  #9a9a9a;
  --danger: #e5534b;
}

.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .12s ease;
}
.btn:hover { background: #4d4d4d; }
.btn:active { transform: scale(.97); }

/* A link styled as a button (「アプリ一覧を開く」). */
a.btn { text-decoration: none; display: inline-block; }

/* Muted icon buttons (the spec's size; they sit on their own row under the name). */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 10px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: #4a4a4a; color: var(--text); }

/* The settings gear is the one control that must read at a glance. */
#settings-btn {
  font-size: 28px;
  overflow: visible;
}

#help-btn { font-size: 20px; font-weight: 700; }

/* "FB" packed edge to edge inside the 36x36 key: bold, squeezed sideways, no extra spacing.
   Sized in px (the 1.8rem of the spec at a 16px root), since this app's root font is 13px. */
#feedback-btn .fb-mark {
  display: inline-block;
  font-size: 23.04px;
  font-weight: 384;
  letter-spacing: -.05em;
  line-height: 1;
  transform: scaleX(.74);
}
#fullscreen-btn[hidden] { display: none; }
.fs-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#fullscreen-btn .fs-exit,
#fullscreen-btn.is-fullscreen .fs-enter { display: none; }
#fullscreen-btn.is-fullscreen .fs-exit { display: block; }

/* ── Settings sheet ──────────────────────────────────────────────────────────── */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, .5);
}
.backdrop[hidden] { display: none; }

.sheet {
  position: fixed;
  z-index: 260;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--sidebar);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .6);
  padding: 16px;
  font-size: 14px;
}
.sheet[hidden] { display: none; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.sheet-title { font-size: 16px; margin: 0; }

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.sheet-label { font-size: 13px; }

.sheet-select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  max-width: 60%;
}

/* ── Changelog overlay ───────────────────────────────────────────────────────── */

#changelogOverlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
}
#changelogOverlay[hidden] { display: none; }

.changelog-card {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: #252525;
  color: #ccc;
  border-radius: 14px;
  padding: 20px 24px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.65);
  font-size: 13px;
  user-select: text;
}

.changelog-title { font-size: 16px; margin: 0 0 8px; color: var(--text); }

.changelog-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

.changelog-entry + .changelog-entry {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
}

.changelog-version { font-size: 13px; margin: 0 0 4px; color: var(--text); }

.changelog-entry ul {
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
  line-height: 1.55;
}

#changelogClose { margin-top: 12px; align-self: center; }

/* ── How to use overlay (same card as the changelog) ─────────────────────── */

#helpOverlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
}
#helpOverlay[hidden] { display: none; }

.help-body { line-height: 1.6; }
.help-body h3 {
  font-size: 13px;
  color: var(--text);
  margin: 14px 0 4px;
}
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin: 6px 0; }
.help-body ol { margin: 4px 0; padding-left: 1.4em; }
.help-body li { margin: 3px 0; }
.help-body strong, .help-body code { color: var(--text); }
.help-body .note { font-size: 12px; color: var(--text-sub); }
.help-keys { border-collapse: collapse; width: 100%; font-size: 12px; }
.help-keys td { padding: 3px 6px; vertical-align: top; }
.help-keys td:first-child { white-space: nowrap; color: #88aadd; padding-right: 16px; width: 1%; }
.help-keys tr:nth-child(even) td { background: rgba(255, 255, 255, 0.03); }
.help-body kbd {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #333;
  color: #cde;
}

#helpClose { margin-top: 12px; align-self: center; }

/* A small dot on ⚙ and on the changelog button until the new version's
 * changelog has been opened once. */
#settings-btn, #changelogBtn { position: relative; }

#settings-btn.has-news::after,
#changelogBtn.has-news::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

/* ── Feedback overlay (same card as the changelog) ──────────────────────── */

#feedbackOverlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
}
#feedbackOverlay[hidden] { display: none; }

.feedback-card { gap: 8px; }
.feedback-card .changelog-title { margin-bottom: 0; }
.feedback-lead, .feedback-note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.feedback-message, .feedback-contact {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  user-select: text;
}
.feedback-message:focus, .feedback-contact:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.feedback-message { resize: vertical; min-height: 120px; }
.feedback-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.feedback-status { margin: 0; min-height: 1.2em; font-size: 12px; font-weight: 700; }
.feedback-status.ok { color: #4ade80; }
.feedback-status.err { color: var(--danger); }
.feedback-actions { display: flex; gap: 8px; justify-content: flex-end; }

#feedbackSend { background: var(--accent); border-color: var(--accent); color: #fff; }
#feedbackSend:disabled { opacity: .6; }

/* ── Quick tooltips (common-ui §10) ─────────────────────────────────────────── */

.quick-tip {
  position: fixed;
  z-index: 400;
  max-width: 260px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: .8rem;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
.quick-tip[hidden] { display: none; }
