/* ==========================================================================
   RANDOMLY CALENDAR KIT v1  —  shared by the three calendar generators
   date-time-tools/calendar-generator.html
   date-time-tools/monthly-calendar-generator.html
   date-time-tools/yearly-calendar-generator.html

   ONE file, three pages. It is a file and not an inlined <style> on purpose:
   three hand-kept copies of a component is how the pages drift, and the
   drifted one is the one users see.

   What lives here:
     .rk-select   a custom listbox that REPLACES a native <select>. The
                  <select> stays in the DOM as the source of truth, so the
                  page's own change listeners keep working untouched.
     .rk-stepper  a joined - / value / + group over input[type=number].
     .rk-dialog   the download sheet. It is a real <dialog> opened with
                  showModal(), which puts it in the browser TOP LAYER --
                  the only way out of .tool-shell-wrapper's stacking
                  context (z-index: 10), which traps any fixed child under
                  the header. Same reason the fullscreen buttons use it.
     .rk-formats  the PNG / PDF and A4 / Letter rows inside that sheet.
                  The controls themselves are .rb-seg from the shared
                  button library, which every one of the three pages
                  already carries; only the placement lives here.

   Tokens come from the page: --accent-cyan --accent-violet --text-main
   --text-muted --card-border --bg-panel, plus the tool bridge's
   --border-color --bg-input --btn-hover-bg. Nothing new is defined that a
   page could disagree with.
   ========================================================================== */

/* ---------- custom select --------------------------------------------- */

.tool-scope .rk-select { position: relative; width: 100%; }

/* The native control still holds the value; it is just never rendered.
   display:none is deliberate over a visually-hidden clip: a clipped select
   still reports an offsetParent, so a checker written the honest way
   (paint, not attributes) could not tell it had gone. Value, options and
   change events all survive display:none. */
.tool-scope .rk-select > select.rk-native { display: none !important; }

.tool-scope .rk-trigger {
    display: flex; align-items: center; gap: 0.5rem; width: 100%;
    min-height: 44px; padding: 0.55rem 0.7rem;
    border-radius: 0.65rem; border: 1px solid var(--border-color);
    background: var(--bg-input); color: var(--text-main);
    font-family: inherit; font-size: 0.95rem; text-align: left; cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.tool-scope .rk-trigger:hover { border-color: color-mix(in srgb, var(--accent-cyan) 45%, var(--border-color)); }
.tool-scope .rk-trigger:focus-visible,
.tool-scope .rk-select.is-open .rk-trigger {
    outline: none; border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.14);
}
.tool-scope .rk-trigger[disabled] { opacity: 0.5; cursor: not-allowed; }

.tool-scope .rk-trigger-val { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-scope .rk-trigger-chev {
    flex: 0 0 auto; width: 16px; height: 16px; color: var(--text-muted);
    fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
}
.tool-scope .rk-select.is-open .rk-trigger-chev { transform: rotate(180deg); color: var(--accent-cyan); }

.tool-scope .rk-pop {
    position: absolute; z-index: 70; top: calc(100% + 6px); left: 0; right: 0;
    max-height: 15.5rem; overflow-y: auto; overscroll-behavior: contain;
    padding: 0.3rem; border-radius: 0.85rem;
    border: 1px solid var(--card-border); background: #ffffff;
    box-shadow: 0 18px 38px -18px rgba(15, 23, 42, 0.4), 0 2px 8px -4px rgba(15, 23, 42, 0.18);
    display: none;
}
:root.dark .tool-scope .rk-pop {
    background: #0e1626; border-color: rgba(51, 65, 85, 0.9);
    box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.7);
}
.tool-scope .rk-select.is-open .rk-pop { display: block; animation: rk-pop-in 0.16s cubic-bezier(0.2, 0.9, 0.3, 1); }
.tool-scope .rk-select.drops-up .rk-pop { top: auto; bottom: calc(100% + 6px); }

@keyframes rk-pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.tool-scope .rk-opt {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 0.55rem; border-radius: 0.55rem;
    font-size: 0.92rem; color: var(--text-main); cursor: pointer;
    transition: background 0.13s ease, color 0.13s ease;
}
.tool-scope .rk-opt:hover,
.tool-scope .rk-opt.is-active { background: var(--btn-hover-bg); }
.tool-scope .rk-opt[aria-selected="true"] {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
    color: #ffffff; font-weight: 700;
}
.tool-scope .rk-opt-tick {
    flex: 0 0 auto; width: 15px; height: 15px; opacity: 0;
    fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
}
.tool-scope .rk-opt[aria-selected="true"] .rk-opt-tick { opacity: 1; }

/* ---------- number stepper -------------------------------------------- */

.tool-scope .rk-stepper {
    /* 40px, not 44: the year sits in a half-width column on two of the three
       pages, and 88px of buttons clipped "2026" down to "202". The row itself
       is 44px tall, so the touch target keeps its height. */
    display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: stretch; min-height: 44px;
    border: 1px solid var(--border-color); border-radius: 0.65rem;
    background: var(--bg-input); overflow: hidden;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.tool-scope .rk-stepper:focus-within { border-color: var(--accent-cyan); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.14); }

.tool-scope .rk-stepper > input {
    width: 100%; min-width: 0; border: 0; padding: 0 2px; background: transparent;
    color: var(--text-main); font-family: var(--font-display); font-size: 0.98rem; font-weight: 700;
    text-align: center; font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
    -moz-appearance: textfield; appearance: textfield;
}
.tool-scope .rk-stepper > input:focus { outline: none; }
.tool-scope .rk-stepper > input::-webkit-outer-spin-button,
.tool-scope .rk-stepper > input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.tool-scope .rk-step-btn {
    display: grid; place-items: center; border: 0; background: transparent; cursor: pointer;
    color: var(--text-muted); padding: 0; touch-action: manipulation;
    transition: background 0.15s ease, color 0.15s ease;
}
.tool-scope .rk-step-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.tool-scope .rk-step-btn:hover { background: var(--btn-hover-bg); color: var(--accent-cyan); }
.tool-scope .rk-step-btn:active { transform: scale(0.92); }
.tool-scope .rk-step-btn[disabled] { opacity: 0.35; cursor: not-allowed; background: none; color: var(--text-muted); }

/* ---------- download dialog -------------------------------------------- */
/* Not scoped under .tool-scope: a <dialog> in the top layer is not a
   descendant of the tool for painting purposes, and it is moved to <body>. */

.rk-dialog {
    /* margin:auto is not decoration. The UA centres a dialog with it, and the
       pages carry a `* { margin: 0 }` reset that reaches into the top layer
       and lands the sheet in the top-left corner. Measured, 2026-08-30. */
    margin: auto; border: 0; padding: 0; background: transparent; color: var(--text-main);
    max-width: min(94vw, 580px); width: 100%; max-height: 92vh; overflow: visible;
}
.rk-dialog::backdrop { background: rgba(2, 6, 23, 0.55); }
.rk-dialog[open] { animation: rk-dlg-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes rk-dlg-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

.rk-card {
    position: relative; overflow: hidden auto; max-height: 92vh; overscroll-behavior: contain;
    background: #ffffff; border: 1px solid var(--card-border); border-radius: 1.25rem;
    padding: 1.5rem 1.35rem 1.25rem; box-shadow: 0 34px 70px -24px rgba(2, 6, 23, 0.55);
    font-family: inherit;
}
:root.dark .rk-card { background: #0e1626; border-color: rgba(51, 65, 85, 0.85); }
/* The brand hairline. Same cyan -> violet the site uses everywhere else. */
.rk-card::before {
    content: ''; position: absolute; inset: 0 0 auto; height: 3px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet));
}

.rk-card h2 { margin: 0 0 0.3rem; font-family: var(--font-display); font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; color: var(--text-main); }
.rk-card > p { margin: 0 0 1rem; font-size: 0.88rem; line-height: 1.5; color: var(--text-muted); }

/* Two up at every width. Stacking them on a phone pushed the Download button
   a screen and a half below the fold -- measured at 412x823, 2026-08-30. */
.rk-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-bottom: 1rem; }

.rk-choice {
    position: relative; display: flex; flex-direction: column; gap: 0.5rem;
    padding: 0.6rem; border-radius: 0.9rem; cursor: pointer; text-align: left;
    border: 1.5px solid var(--border-color); background: var(--bg-input);
    font-family: inherit; color: var(--text-main);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.rk-choice:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent-cyan) 50%, var(--border-color)); }
.rk-choice[aria-pressed="true"] { border-color: var(--accent-cyan); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.16); }
.rk-choice:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; }

/* The preview is the real calendar, drawn by the same renderer that makes
   the file -- so what you pick is literally what you get. */
.rk-choice canvas { display: block; width: 100%; height: auto; border-radius: 0.55rem; border: 1px solid var(--border-color); }
.rk-choice strong { font-size: 0.9rem; font-weight: 700; }
.rk-choice small { display: block; font-size: 0.76rem; color: var(--text-muted); line-height: 1.35; margin-top: 0.1rem; }
.rk-choice-badge {
    position: absolute; top: 0.85rem; right: 0.85rem; width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center; opacity: 0; transform: scale(0.6);
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet)); color: #fff;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.rk-choice-badge svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rk-choice[aria-pressed="true"] .rk-choice-badge { opacity: 1; transform: none; }

/* ---------- format and paper, inside the sheet ------------------------- */
/* The controls are .rb-seg out of the shared button library, which the three
   pages already carry in their <style id="rb-lib"> block. Nothing about the
   control is redefined here -- only where it sits. */

.rk-formats { display: grid; gap: 0.55rem; margin-bottom: 1rem; }

.rk-format-row { display: flex; align-items: center; gap: 0.75rem; }

/* [hidden] is an author-level display:none, so the rule above would win and
   the Paper row would stay visible on the PNG tab. Specificity, not
   !important: traps/hidden-attribute-vs-display.md. */
.rk-format-row[hidden] { display: none; }

.rk-format-label {
    flex: 0 0 auto; min-width: 3.1rem;
    font-size: 0.8rem; font-weight: 700; letter-spacing: 0.01em; color: var(--text-muted);
}

/* .tool-scope .rb-seg { width: 100% } does not reach the top layer, so the
   sheet states its own. */
.rk-dialog .rb-seg { width: 100%; }
.rk-dialog .rb-seg .rb-seg-btn { flex: 1 1 0; }

.rk-note {
    display: flex; align-items: center; gap: 0.5rem; margin: 0 0 1rem;
    font-size: 0.78rem; line-height: 1.45; color: var(--text-muted);
}
.rk-note svg { flex: 0 0 auto; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--accent-cyan); }

.rk-actions { display: flex; justify-content: flex-end; gap: 0.6rem; flex-wrap: wrap; }

@media (max-width: 520px) {
    .rk-card { padding: 1.25rem 0.95rem 1rem; }
    .rk-card h2 { font-size: 1.05rem; }
    .rk-card > p { font-size: 0.82rem; }
    .rk-choice { padding: 0.45rem; gap: 0.4rem; }
    .rk-choice small { font-size: 0.71rem; }
    .rk-choice-badge { top: 0.7rem; right: 0.7rem; width: 18px; height: 18px; }
    .rk-format-row { gap: 0.5rem; }
    .rk-format-label { min-width: 2.7rem; font-size: 0.75rem; }
    .rk-actions > .rb { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
    .tool-scope .rk-select.is-open .rk-pop,
    .rk-dialog[open] { animation: none; }
    .tool-scope .rk-trigger-chev,
    .rk-choice { transition: none; }
}
