* { box-sizing: border-box; }

/* .group sets display:flex, which would otherwise defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background: #1b1b1b;
  color: #eee;
}

body {
  display: flex;
  flex-direction: column;
}

/* --- toolbar / nav --- */

#toolbar, #navbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #262626;
  border-bottom: 1px solid #3a3a3a;
  flex-wrap: wrap;
}

#navbar { padding: 6px 10px; }

.group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.group + .group { margin-left: 14px; }

/* App name + version: the same look in every yukmmz.github.io app. */
.app-brand {
  align-items: baseline;
  gap: .45em;
  white-space: nowrap;
}

.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;
}
.group.right { margin-left: auto; }
.spacer { flex: 1; }

button {
  padding: 6px 12px;
  font-size: 14px;
  color: #eee;
  background: #3a3a3a;
  border: 1px solid #4d4d4d;
  border-radius: 4px;
  cursor: pointer;
}

button:hover:not(:disabled) { background: #474747; }
button:disabled { opacity: 0.4; cursor: default; }
button.mode.active { background: #2f6feb; border-color: #2f6feb; }

.label, .hint {
  font-size: 13px;
  color: #9a9a9a;
}

#frame-label {
  min-width: 96px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

input[type="number"], input[type="color"] {
  background: #1b1b1b;
  color: #eee;
  border: 1px solid #4d4d4d;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
}

input[type="number"] { width: 88px; }
input[type="color"] { width: 44px; height: 28px; padding: 2px; }

/* --- stage --- */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #101010;
}

/* The canvas covers the whole stage; the frame is positioned inside it by the
   view transform (zoom / pan), so panning never moves the element itself. */
#canvas {
  width: 100%;
  height: 100%;
  display: none;
  cursor: crosshair;
  touch-action: none;
}

#placeholder { color: #888; font-size: 15px; }

/* "Calibration OK", centred over the frame for a moment */
.calib-ok {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 28px;
  border-radius: 12px;
  background: rgba(31, 138, 95, 0.92);
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.calib-ok[hidden] { display: none; }

/* --- rulers --- */
.ruler-btn { min-width: 30px; font-weight: bold; }
.ruler-edit.active { background: #22b8cf; border-color: #22b8cf; color: #08262b; }

/* The "Delete this ruler" button shown at the pointer on a right-click. */
.ruler-menu {
  position: fixed;
  z-index: 50;
  padding: 6px 12px;
  font-size: 13px;
  background: #fff;
  color: #c92a2a;
  border: 1px solid #c92a2a;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.ruler-menu[hidden] { display: none; }

/* --- seek bar --- */

#seek-row {
  padding: 6px 12px 8px;
  background: #262626;
  border-bottom: 1px solid #3a3a3a;
}

#seek {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

#seek::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #3a3a3a;
}

#seek::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #3a3a3a;
}

#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: none;
  border-radius: 50%;
  background: #2f6feb;
}

#seek::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: #2f6feb;
}

#seek:focus-visible { outline: 2px solid #4680f0; outline-offset: 4px; }

#frame-step { width: 68px; }

#navbar .sep {
  width: 1px;
  height: 20px;
  margin: 0 8px;
  background: #3a3a3a;
}

#zoom-label {
  min-width: 54px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

#marker-size { width: 64px; }

#navbar button { padding: 5px 10px; }

/* --- log / status --- */

#logbox {
  height: 96px;
  overflow-y: auto;
  background: #1f1f1f;
  border-top: 1px solid #3a3a3a;
  padding: 6px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #c8c8c8;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

#log div { white-space: pre-wrap; }
#log div.warn { color: #ffcc66; }
#log div.err { color: #ff8080; }

#status {
  padding: 6px 10px;
  font-size: 13px;
  color: #aaa;
  background: #262626;
  border-top: 1px solid #3a3a3a;
}


/* --- guide bar: always says what to do next --- */

#guide {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  background: #16324f;
  border-bottom: 1px solid #24507d;
  color: #dceaff;
  font-size: 15px;
}

/* one colour per mode, so the bar tells at a glance what a click will do */
#guide.mode-calib { background: #16324f; border-bottom-color: #24507d; }
#guide.mode-add { background: #2c3d17; border-bottom-color: #4a6526; color: #e3f5c4; }
#guide.mode-del { background: #4a3410; border-bottom-color: #7a5416; color: #ffe0a3; }
/* tones come last so they win over the mode colour */
#guide.warn { background: #4a3410; border-bottom-color: #7a5416; color: #ffe0a3; }
#guide.ok { background: #1f8a5f; border-bottom-color: #2fb37c; color: #fff; }

#guide-step {
  flex: none;
  padding: 2px 10px;
  border-radius: 999px;
  background: #2f6feb;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#guide.mode-calib #guide-step { background: #2f6feb; }
#guide.mode-add #guide-step { background: #7cb342; }
#guide.mode-del #guide-step { background: #b3730c; }
#guide.warn #guide-step { background: #b3730c; }
#guide.ok #guide-step { background: #fff; color: #1f8a5f; }

#guide-text { font-weight: 600; }

#guide-sub {
  color: inherit;
  opacity: 0.75;
  font-size: 13px;
}

/* --- dialogs --- */


dialog {
  background: #262626;
  color: #eee;
  border: 1px solid #4d4d4d;
  border-radius: 8px;
  padding: 20px 24px;
  max-width: 640px;
  line-height: 1.6;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

/* Modal dialogs are centred with margin:auto — overriding the margins parks the dialog
   in the corner furthest from the point being clicked, so it never hides it. */
dialog.pos-left { margin-left: 32px; margin-right: auto; }
dialog.pos-right { margin-right: 32px; margin-left: auto; }
/* clears the toolbar + guide bar + navbar, so the dialog sits over the image area only */
dialog.pos-top { margin-top: 140px; margin-bottom: auto; }
dialog.pos-bottom { margin-bottom: 32px; margin-top: auto; }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog h3 { margin: 18px 0 6px; font-size: 14px; color: #9ec5ff; }
dialog label { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 14px; }
dialog .lead { margin: 6px 0 14px; font-size: 14px; }
dialog .fields { display: flex; gap: 18px; margin: 14px 0; }
dialog .fields label { margin: 0; }
dialog .fields input[type="number"] { width: 130px; font-size: 15px; padding: 6px 8px; }
dialog button.primary { background: #2f6feb; border-color: #2f6feb; }
dialog button.primary:hover { background: #4680f0; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 18px 0 0; padding: 0; }
dialog table { border-collapse: collapse; font-size: 13.5px; }
dialog td { padding: 2px 14px 2px 0; }
dialog code { background: #1b1b1b; padding: 1px 5px; border-radius: 3px; font-size: 12.5px; }
dialog ol, dialog ul { margin: 6px 0; padding-left: 22px; font-size: 14px; }

/* ---------- common header / settings pieces (same in every yukmmz.github.io app) ----------
   Shapes follow multitask-timer; colours are this app's fixed dark palette. */

:root {
  --card: #262626;
  --border: #3a3a3a;
  --text: #eee;
  --bg: #1b1b1b;
  --muted: #9a9a9a;
  --danger: #ff6b6b;
  --radius: 16px;
  --shadow-run: 0 6px 22px rgba(0, 0, 0, .55);
}

/* The version next to the app name opens the changelog. */
.app-version { cursor: pointer; }
.app-version:hover { text-decoration: underline; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-size: 1.1rem;
  line-height: 1;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover:not(:disabled) { color: var(--text); }

/* The settings gear is the one control that must read at a glance. */
#settings-btn {
  font-size: 2.1rem;
  line-height: 1;
  overflow: visible;
}

#help-btn { font-size: 1.35rem; font-weight: 700; }
/* "FB" packed edge to edge inside the 36x36 key: bold, squeezed sideways, no extra spacing.
   Buttons here use the browser default (Arial); the reference font keeps the mark 23px wide. */
#feedback-btn .fb-mark {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  display: inline-block;
  font-size: 1.44rem;
  font-weight: 384;
  letter-spacing: -.05em;
  line-height: 1;
  transform: scaleX(.74);
}
#fullscreen-btn[hidden] { display: none; }
/* Full-screen icon: corners out to expand, corners in (while full screen) to shrink */
.fs-icon {
  width: 22px;
  height: 22px;
  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; }

/* A link styled as a button (「アプリ一覧を開く」). */
a.btn {
  display: inline-block;
  padding: 6px 12px;
  font-size: 14px;
  color: var(--text);
  background: #3a3a3a;
  border: 1px solid #4d4d4d;
  border-radius: 4px;
  text-decoration: none;
}

a.btn:hover { background: #474747; }
.btn-danger { color: var(--danger); }

/* ---------- settings sheet ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .5);
}

.sheet {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-run);
  padding: 16px;
}

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

.sheet-title { font-size: 1rem; margin: 0; }

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

label.sheet-row { cursor: pointer; }

.sheet-label { font-size: .9rem; line-height: 1.4; }

.sheet-label small {
  display: block;
  font-size: .75rem;
  color: var(--muted);
}

.sheet-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: #2f6feb;
}

.sheet-row input[type="color"],
.sheet-row input[type="number"] { flex: 0 0 auto; }
.sheet-row input[type="color"]:disabled { opacity: .35; }
.sheet-row input[type="number"] { width: 72px; }

.sheet-select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #1b1b1b;
  border: 1px solid #4d4d4d;
  border-radius: 6px;
  padding: 5px 8px;
  max-width: 60%;
}

/* ---------- QR overlay ---------- */

#qrOverlay,
#changelogOverlay,
#helpOverlay,
#feedbackOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
}

.qrcard {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-run);
  padding: 20px;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
}

.qrrow {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.qrcol { flex: 0 1 210px; }

.qrlabel {
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

/* The SVG is drawn on white; keep it that way on the dark card so it stays scannable. */
.qrImg {
  width: 100%;
  max-width: 190px;
  height: auto;
  background: #fff;
  border-radius: 8px;
}

.qrurl {
  font-size: .7rem;
  color: var(--muted);
  word-break: break-all;
  margin-top: 4px;
}

#qrClose { margin-top: 16px; }

/* ---------- changelog overlay ---------- */

.changelog-card {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  text-align: left;
}

.changelog-title { font-size: 1rem; margin: 0 0 8px; }

.changelog-list {
  overflow-y: auto;
  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: .9rem; margin: 0 0 4px; }

.changelog-entry ul {
  margin: 0;
  padding-left: 1.2em;
  font-size: .85rem;
  line-height: 1.5;
  color: var(--muted);
}

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

/* ---------- help overlay (使い方): the changelog card, a little wider for the tables ---------- */

.help-card { width: min(640px, calc(100vw - 32px)); max-width: none; }

.help-body { font-size: .9rem; line-height: 1.6; padding-right: 4px; }
.help-body p { margin: 6px 0; }
.help-body .hint { font-size: .8rem; color: var(--muted); }
.help-body h3 { margin: 16px 0 6px; font-size: .9rem; color: #9ec5ff; }
.help-body h3:first-child { margin-top: 0; }
.help-body ol, .help-body ul { margin: 6px 0; padding-left: 22px; }
.help-body table { border-collapse: collapse; font-size: .85rem; }
.help-body td { padding: 2px 14px 2px 0; vertical-align: top; }
.help-body code { background: #1b1b1b; padding: 1px 5px; border-radius: 3px; font-size: .8rem; }

#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 (FB): the changelog card holding a small form ---------- */

.feedback-card { gap: 8px; }
.feedback-lead, .feedback-note { margin: 0; font-size: .85rem; color: var(--muted); }
.feedback-message, .feedback-contact {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: .95rem;
  padding: 8px 10px;
  border: 1px solid #4d4d4d;
  border-radius: 10px;
  background: #1b1b1b;
  color: var(--text);
}
.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: .85rem; 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: #2f6feb; border-color: #2f6feb; color: #fff; }
#feedbackSend:hover:not(:disabled) { background: #4680f0; }
#feedbackSend:disabled { opacity: .6; }

/* ---------- quick tooltip (common spec 10): mouse only, 0.5 s; inverted colours ---------- */
.quick-tip {
  position: fixed;
  z-index: 100;  /* above the overlays (60) */
  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: var(--shadow-run);
}
.quick-tip[hidden] { display: none; }
