/* Chart maker page (app/views/chart_makers/show.html.erb). Loaded only there. The chart itself
   (.cm-page) is sized in millimetres and drawn by chart_maker_controller.js; on screen it is scaled
   into the preview column, in print it is the only thing on the page. */

/* ---------- page ---------- */
.cm-hero h1 { font-size: clamp(2rem, 4.4vw, 3rem); max-width: 22ch; margin: 0.35em 0 0.35em; }
.cm-hero .lead { max-width: 62ch; margin: 0 0 0.6em; }
.cm-note { margin: 0; font-weight: 700; color: var(--ink-strong); }
.cm-noscript { font-weight: 700; }
.cm-app { padding: 8px 0 56px; }
.cm-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 36px; align-items: start; }

.cm-controls { display: grid; gap: 18px; min-width: 0; }
.cm-step { margin: 0; padding: 18px 20px 20px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--card); min-width: 0; }
.cm-step legend { display: flex; align-items: center; gap: 10px; padding: 0 6px; margin-left: -6px; font-weight: 800; font-size: 1.15rem; color: var(--ink-strong); }
.cm-num { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; background: var(--honey); color: var(--ink-strong); font-size: 0.95rem; }
.cm-label { display: block; font-weight: 700; color: var(--ink-strong); margin: 0 0 6px; }
.cm-hint { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.cm-input {
  width: 100%; min-height: 46px; padding: 10px 14px; border: 1.5px solid #e6d6bd; border-radius: 12px;
  background: #fff; font: inherit; color: var(--ink-strong);
}
.cm-input:focus-visible { outline: 3px solid var(--link); outline-offset: 1px; }
.cm-select { appearance: none; padding-right: 40px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='%23776750' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center / 16px; }
.cm-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.cm-row > div { flex: 1 1 180px; }
.btn.cm-ghost { background: var(--card); box-shadow: inset 0 0 0 1.5px #f5c542; border-bottom-color: #f5c542; }

/* layout picker */
.cm-layouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cm-layout { position: relative; display: block; cursor: pointer; }
.cm-layout input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.cm-layout-card { display: flex; align-items: center; gap: 12px; height: 100%; padding: 10px 12px; border: 2px solid var(--line); border-radius: 14px; background: #fff; }
.cm-layout input:checked + .cm-layout-card { border-color: var(--honey); background: #fff8e6; box-shadow: 0 3px 0 var(--honey-edge); }
.cm-layout input:focus-visible + .cm-layout-card { outline: 3px solid var(--link); outline-offset: 2px; }
.cm-layout-icon { width: 38px; height: 48px; flex: none; }
.cm-layout-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.cm-layout-text b { color: var(--ink-strong); }
.cm-layout-text span { font-size: 0.84rem; color: var(--muted); }

/* tasks */
.cm-subtitle { font-size: 1.02rem; margin: 18px 0 8px; }
.cm-selected { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: cm; }
.cm-item { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 10px; border-radius: 12px; background: #fff8e6; border: 1.5px solid #fbe3a6; }
.cm-item > img { width: 24px; height: 24px; flex: none; }
.cm-item .cm-dot { width: 10px; height: 10px; margin: 0 7px; border-radius: 50%; background: var(--honey); flex: none; }
.cm-item-name { flex: 1; min-width: 0; font-weight: 700; color: var(--ink-strong); line-height: 1.25; overflow-wrap: anywhere; }
.cm-item-controls { display: flex; gap: 4px; flex: none; }
.cm-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0;
  border: 1.5px solid #f1d58a; border-radius: 10px; background: #fff; color: var(--ink); cursor: pointer;
}
.cm-icon-btn svg { width: 16px; height: 16px; }
.cm-icon-btn img { width: 22px; height: 22px; }
.cm-icon-btn:hover:not(:disabled) { background: #fff3d6; }
.cm-icon-btn:disabled { opacity: 0.35; cursor: default; }
.cm-icon-btn:focus-visible { outline: 3px solid var(--link); outline-offset: 1px; }
.cm-remove { color: #b8392f; }
.cm-warning { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; background: #ffe4e1; color: #8f2a22; font-weight: 700; font-size: 0.92rem; }
.cm-custom { margin-top: 14px; }
.cm-custom-row { display: flex; gap: 8px; }
.cm-custom-row .btn { flex: none; }
.cm-library { display: grid; gap: 12px; }
.cm-category h4 { margin: 0 0 6px; font-size: 0.88rem; text-transform: none; color: var(--muted); font-weight: 800; }
.cm-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.cm-pick {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 12px 4px 6px;
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff; font: inherit; font-size: 0.9rem;
  font-weight: 700; color: var(--ink-strong); cursor: pointer; text-align: left; line-height: 1.2;
}
.cm-pick img { width: 28px; height: 28px; flex: none; }
.cm-pick:hover { border-color: #f5c542; }
.cm-pick[aria-pressed="true"] { background: #fff3d6; border-color: var(--honey); box-shadow: inset 0 0 0 1px var(--honey); }
.cm-pick[aria-pressed="true"]::after { content: ""; width: 14px; height: 14px; flex: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3.2 3L13 4.5' fill='none' stroke='%238a5f00' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain; }
.cm-pick:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }

/* options */
.cm-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; color: var(--ink-strong); cursor: pointer; }
.cm-check input { width: 22px; height: 22px; accent-color: var(--honey-deep); flex: none; }
.cm-option { margin-top: 12px; }
.cm-option[hidden], [data-chart-maker-target][hidden] { display: none; }
.cm-segments { display: flex; flex-wrap: wrap; gap: 6px; }
.cm-segments label { position: relative; cursor: pointer; }
.cm-segments input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.cm-segments span { display: inline-flex; align-items: center; justify-content: center; min-width: 56px; min-height: 44px; padding: 6px 16px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 800; color: var(--ink-strong); }
.cm-segments input:checked + span { border-color: var(--honey); background: #fff3d6; }
.cm-segments input:focus-visible + span { outline: 3px solid var(--link); outline-offset: 2px; }

/* preview */
.cm-preview { position: sticky; top: 84px; min-width: 0; scroll-margin-top: 84px; }
.cm-preview-inner { padding: 18px; border-radius: var(--radius); background: var(--cream-deep); }
.cm-preview-title { font-size: 1.15rem; margin: 0 0 12px; }
.cm-stage { position: relative; width: 100%; overflow: hidden; border-radius: 6px; box-shadow: 0 0 0 1.5px #eadbc2, 6px 6px 0 #f1deb4; background: #fff; }
.cm-sheet { transform-origin: 0 0; width: max-content; }
.cm-placeholder { display: block; width: 100%; height: auto; }
.cm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.cm-print { display: inline-flex; align-items: center; gap: 8px; }
.cm-print svg { width: 20px; height: 20px; }
.cm-bar { display: none; }

/* below the maker */
.cm-ticks { max-width: 760px; }
.cm-ticks li { font-weight: 400; color: var(--ink); }
.cm-faq-title { margin-top: 1.6em; }
.cm-faq { max-width: 760px; }
.cm-faq h3 { font-size: 1.1rem; margin: 1.1em 0 0.3em; }
.cm-faq p { margin: 0; }
.cm-ready { margin-top: 1.6em; font-weight: 700; }

@media (max-width: 900px) {
  .cm-grid { grid-template-columns: 1fr; }
  .cm-preview { position: static; }
  .cm-bar {
    display: flex; gap: 8px; justify-content: center; position: sticky; bottom: 0; z-index: 15;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgba(255, 248, 240, 0.96); border-top: 1.5px solid var(--line);
  }
  .cm-bar-preview { gap: 6px; }
  .cm-bar-preview svg { width: 18px; height: 18px; flex: none; }
}
/* Long print labels (de, pl, sv, da, nl, fr) keep one line: the preview link shrinks to its icon. */
@media (max-width: 560px) {
  .cm-bar-preview { flex: none; width: 48px; padding-left: 0; padding-right: 0; }
  .cm-bar-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .cm-bar [data-action="chart-maker#print"] { flex: 1; white-space: nowrap; padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 480px) {
  .cm-step { padding: 14px 14px 16px; }
  .cm-layouts { grid-template-columns: 1fr; }
  .cm-preview-inner { padding: 12px; }
  .cm-item-controls { gap: 2px; }
  .cm-icon-btn { width: 36px; height: 40px; }
}

/* ---------- the chart (mm, same look as the printables v2 charts) ---------- */
.cm-page {
  --honey: #ffb800; --soft: #fff4d9; --honey-line: #f6cd6a; --ink: #4a4238; --ink-strong: #2f2a23; --muted: #8a7a63; --line: #eadfcd;
  position: relative; box-sizing: border-box; padding: 10mm 11mm 7mm; display: flex; flex-direction: column; overflow: hidden;
  background: #fff; color: var(--ink); line-height: 1.2;
  font-family: "Nunito", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans JP", Arial, sans-serif;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.cm-page * { box-sizing: border-box; }
.cm-head { display: flex; align-items: center; gap: 5mm; padding-bottom: 3mm; border-bottom: 1.2mm solid var(--honey); }
.cm-habi { width: 26mm; height: 26mm; object-fit: contain; flex: none; }
.cm-title { flex: 1; min-width: 0; margin: 0; max-height: 22mm; overflow: hidden; font-size: 24pt; line-height: 1.1; font-weight: 800; color: var(--ink-strong); }
.cm-fields { margin-left: auto; display: grid; gap: 3mm; width: 66mm; flex: none; font-weight: 700; font-size: 11pt; }
.cm-field { display: flex; align-items: flex-end; gap: 2mm; white-space: nowrap; min-width: 0; }
.cm-line { flex: 1; min-width: 12mm; height: 7mm; border-bottom: 0.35mm solid var(--ink); }
.cm-line.cm-name { height: 9mm; overflow: hidden; white-space: nowrap; font-size: 18pt; font-weight: 800; color: var(--ink-strong); line-height: 9mm; padding-left: 1mm; }
.cm-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.cm-week-grid { flex: 1; min-height: 0; display: grid; gap: 1.6mm; margin-top: 4mm; }
.cm-day { display: flex; align-items: center; justify-content: center; border-radius: 2.5mm; background: var(--soft); font-weight: 800; font-size: 10.5pt; color: var(--ink-strong); text-align: center; line-height: 1.1; overflow: hidden; }
.cm-cell { display: flex; align-items: center; gap: 3mm; padding: 1mm 3mm 1mm 2mm; border-radius: 3mm; background: var(--soft); min-height: 0; min-width: 0; overflow: hidden; }
.cm-cell img { width: var(--icon); height: var(--icon); flex: none; }
.cm-text { flex: 1; min-width: 0; font-weight: 800; font-size: var(--label); line-height: 1.15; color: var(--ink-strong); overflow-wrap: break-word; hyphens: auto; }
.cm-words .cm-cell { padding-left: 3.5mm; }
.cm-picture { flex: none; width: var(--icon); height: var(--icon); border: 0.45mm dashed var(--honey-line); border-radius: 2.5mm; background: #fff; }
.cm-write { flex: 1; align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.cm-write i { display: block; height: 0; border-bottom: 0.35mm solid #d9cbb4; margin-top: 50%; }
.cm-blank .cm-write i { margin: auto 0 2.5mm; }
.cm-tick { display: flex; align-items: center; justify-content: center; border: 0.35mm solid var(--line); border-radius: 3mm; min-height: 0; }
.cm-tick::after { content: ""; height: min(76%, var(--box)); aspect-ratio: 1; border: 0.5mm solid #fbe1a0; border-radius: 50%; }

/* goal box with Buddy peeking out from behind the drawing space */
.cm-goal, .cm-working { position: relative; margin-top: 4mm; height: 44mm; flex: none; display: flex; padding: 3.5mm 5mm; border: 0.8mm solid var(--honey); border-radius: 5mm; }
.cm-page-sticker .cm-goal { height: 46mm; }
.cm-goal-main, .cm-working-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2.5mm; padding-right: 2mm; }
.cm-goal-title, .cm-working-text strong { display: flex; align-items: center; gap: 3mm; font-weight: 800; font-size: 16pt; color: var(--ink-strong); }
.cm-goal-title img, .cm-working-text strong img { width: 12mm; height: 12mm; flex: none; }
.cm-goal .cm-field, .cm-working .cm-field { font-size: 11.5pt; font-weight: 700; white-space: normal; }
.cm-draw { position: relative; z-index: 1; width: 58mm; flex: none; border: 0.5mm dashed var(--honey-line); border-radius: 4mm; background: #fff; display: flex; align-items: flex-end; justify-content: center; padding: 0 3mm 2.5mm; font-size: 9pt; color: var(--muted); text-align: center; }
.cm-peek { position: relative; width: 31mm; flex: none; display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-end; }
.cm-peek img { width: 28mm; height: 30mm; object-fit: contain; object-position: right bottom; margin-right: -0.4mm; }
.cm-bubble { position: absolute; z-index: 2; top: -1mm; right: 2mm; width: max-content; max-width: 44mm; padding: 1.3mm 2.4mm; border-radius: 3mm; background: var(--soft); border: 0.4mm solid var(--honey-line); font-weight: 800; font-size: 8.5pt; line-height: 1.15; color: var(--ink-strong); text-align: center; }
.cm-bubble::after { content: ""; position: absolute; bottom: -1.6mm; right: 9mm; width: 2.6mm; height: 2.6mm; background: var(--soft); border-right: 0.4mm solid var(--honey-line); border-bottom: 0.4mm solid var(--honey-line); transform: rotate(45deg); }

/* morning and evening routine */
.cm-routine { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-top: 4mm; }
.cm-routine-wide { grid-template-columns: 1fr; }
.cm-column { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.cm-column-title { display: flex; align-items: center; gap: 2.5mm; margin: 0 0 2.5mm; font-size: 16pt; font-weight: 800; color: var(--ink-strong); }
.cm-column-title img { width: 11mm; height: 11mm; }
.cm-steps { flex: 1; min-height: 0; list-style: none; margin: 0; padding: 0; display: grid; grid-auto-rows: minmax(0, 34mm); align-content: start; gap: 3mm; }
.cm-rstep { display: flex; align-items: stretch; gap: 2mm; min-height: 0; max-height: 34mm; }
.cm-n { flex: none; width: 8mm; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13pt; color: #b98500; }
.cm-rstep .cm-cell { flex: 1; }
.cm-box { flex: none; align-self: center; width: 11mm; height: 11mm; border: 0.6mm solid var(--honey-line); border-radius: 2.5mm; background: #fff; }
.cm-routine-wide .cm-box { width: 14mm; height: 14mm; }

/* sticker chart and token board */
.cm-earn { margin-top: 4mm; flex: none; }
.cm-earn-title { margin: 0 0 2mm; font-weight: 800; font-size: 13pt; color: var(--ink-strong); }
.cm-chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2mm; --icon: 10mm; --label: 11pt; }
.cm-chip { height: 14mm; }
.cm-write-lines { display: flex; flex-direction: column; gap: 3mm; }
.cm-write-lines i { margin: 0; height: 7mm; }
.cm-stickers { flex: 1; min-height: 0; display: grid; gap: 2mm; margin-top: 4mm; }
.cm-sticker, .cm-hex { width: 100%; height: 100%; display: block; }
.cm-sticker circle { fill: #fff; stroke: var(--honey-line); stroke-width: 2.4; }
.cm-sticker text, .cm-hex text { font-family: inherit; font-weight: 800; fill: #fbe1a0; font-size: 26px; }
.cm-board { flex: 1; min-height: 0; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4mm; margin-top: 4mm; }
.cm-board .cm-hex { width: var(--hex, 30mm); height: calc(var(--hex, 30mm) * 0.87); flex: none; }
.cm-hex polygon { fill: #fff; stroke: var(--honey); stroke-width: 3; stroke-linejoin: round; }
.cm-hex text { font-size: 30px; }
.cm-cutouts { margin-top: 4mm; flex: none; padding: 3mm 4mm 3.5mm; border: 0.5mm dashed var(--muted); border-radius: 3mm; }
.cm-cutouts-head { display: flex; align-items: center; gap: 2mm; font-weight: 700; font-size: 10pt; color: var(--muted); margin-bottom: 2.5mm; }
.cm-cutouts-head img { width: 6mm; height: 6mm; }
.cm-cutouts-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 2.5mm 4mm; }
.cm-cutouts-row img { width: var(--token); height: var(--token); object-fit: contain; }

/* footer: tip, Buddy on the brand strip, QR code to the landing page */
.cm-foot { position: relative; margin-top: 2.5mm; min-height: 10mm; display: flex; align-items: flex-end; padding-right: 46mm; flex: none; }
.cm-tip { margin: 0 0 1.5mm; font-size: 10.5pt; font-weight: 700; color: var(--ink); line-height: 1.25; }
.cm-buddy-sit { position: absolute; right: 25mm; bottom: -4.5mm; width: 17mm; height: 16mm; object-fit: contain; object-position: center bottom; }
.cm-strip { position: relative; z-index: 2; flex: none; display: flex; align-items: center; gap: 3mm; padding: 2mm 2.5mm 2mm 3mm; border-radius: 3.5mm; background: var(--soft); }
.cm-app-icon { width: 11mm; height: 11mm; border-radius: 2.6mm; flex: none; }
.cm-strip-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3mm; line-height: 1.2; }
.cm-strip-text b { font-size: 11pt; font-weight: 800; color: var(--ink-strong); }
.cm-app-line { font-size: 8.5pt; font-weight: 700; color: var(--ink); }
.cm-credit { font-size: 6.5pt; color: var(--muted); }
.cm-qr { flex: none; width: 16.5mm; height: 16.5mm; padding: 1.3mm; background: #fff; border-radius: 1.5mm; }
.cm-qr svg { display: block; width: 100%; height: 100%; }

/* ---------- print: only the chart, at its real size ---------- */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body > header, body > footer, .flash, main > *:not(.cm-app), .cm-app > *:not(.cm-grid), .cm-controls,
  .cm-preview-title, .cm-actions, .cm-preview .cm-hint, .cm-bar { display: none !important; }
  .cm-app, .cm-grid, .cm-preview, .cm-preview-inner { display: block !important; position: static !important; padding: 0 !important; margin: 0 !important; background: none !important; max-width: none !important; }
  .cm-stage { height: auto !important; overflow: visible !important; box-shadow: none !important; border-radius: 0 !important; }
  .cm-sheet { transform: none !important; }
  .cm-page { break-after: avoid; break-inside: avoid; }
}
@media (max-width: 360px) {
  .cm-bar [data-action="chart-maker#print"] { font-size: 0.8rem; padding-left: 8px; padding-right: 8px; }
}
