/* My clan (pages/clans-manage.js): sign-in explainer, Create / Join forms, the clan card, roster,
   invite code, clan home, Clan details and the owner's tools. Panels, buttons, the page head and the
   clan card's tag badge and stat grid come from site.css and clans.css. Square corners throughout;
   the only colours outside the palette are the clan colour swatches, set inline from the API's list. */

.cm-page [hidden] { display: none !important; }
/* Buttons and fields start from nothing; .btn and the rules below style them (no specificity, so
   .btn-ghost, .btn-outline and the rest win). */
:where(.cm-page) :where(button) { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:where(.cm-page) :where(input, select, textarea) { font: inherit; }
.cm-page .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cm-page .btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }

.cm-flash {
    margin: 0; padding: 12px 16px; border-left: 2px solid var(--accent);
    background: var(--panel-bg); font-weight: 700; font-size: 15px; color: var(--text);
}

/* ------------------------------------------------------------------ type */

.cm-h2 {
    margin: 0; font-family: var(--font-display); font-stretch: var(--display-stretch); font-weight: 900;
    font-size: clamp(22px, 2.4vw, 30px); line-height: 1.05; text-transform: uppercase; overflow-wrap: anywhere; hyphens: auto;
}
.cm-h3 {
    margin: 0; font-family: var(--font-display); font-stretch: var(--display-stretch); font-weight: 900;
    font-size: 18px; line-height: 1.1; text-transform: uppercase; overflow-wrap: anywhere;
}
.cm-h4 { margin: 0; font-weight: 800; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); overflow-wrap: anywhere; }
.cm-text { margin: 0; max-width: 62ch; font-size: 15px; line-height: 1.5; color: var(--text-3); overflow-wrap: anywhere; }
.cm-hint { font-size: 12px; font-weight: 600; line-height: 1.4; color: var(--text-4); overflow-wrap: anywhere; }
.cm-muted { margin: 0; font-weight: 600; font-size: 14px; color: var(--text-3); overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ signed out */

.cm-signin { padding: 32px; display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.cm-signin-btn { margin-top: 6px; min-height: 52px; }
.cm-signin-btn > svg:first-child { width: 20px; height: 20px; }
.cm-signin-btn > span { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ boxes and forms */

.cm-split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.cm-box { padding: 22px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.cm-box-head { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cm-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cm-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.cm-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; margin: 0; padding: 0; border: 0; }
.cm-label { padding: 0; font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); overflow-wrap: anywhere; }
.cm-field input, .cm-field select, .cm-field textarea {
    width: 100%; min-width: 0; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line-strong);
    background: color-mix(in srgb, var(--obsidian) 80%, transparent); color-scheme: dark;
    font-family: var(--font-body); font-weight: 600; font-size: 16px; color: var(--text); /* 16px: iOS does not zoom */
}
.cm-field textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.cm-field select { cursor: pointer; }
.cm-field input::placeholder, .cm-field textarea::placeholder { color: var(--text-5); }
.cm-field input:focus, .cm-field select:focus, .cm-field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.cm-code-input, .cm-tag-input { text-transform: uppercase; letter-spacing: 0.08em; }
.cm-inline { display: flex; gap: 8px; min-width: 0; }
.cm-inline input { flex: 1 1 auto; }
.cm-inline .btn { flex: none; min-height: 44px; }
.cm-submit { align-self: flex-start; }
.cm-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* The clan colour: chips with a square swatch; the chosen one takes the teal edge. */
.cm-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.cm-swatch {
    position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 12px 6px 9px;
    border: 1px solid var(--line-strong); cursor: pointer; font-weight: 700; font-size: 13px; color: var(--text-2);
}
.cm-swatch input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cm-swatch:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); color: var(--text); }
.cm-swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.cm-sw { flex: none; width: 14px; height: 14px; background: var(--sw); box-shadow: inset 0 0 0 1px var(--line-overlay); }

.cm-err, .cm-ok { margin: 0; padding: 10px 14px; font-weight: 700; font-size: 14px; line-height: 1.4; color: var(--text); overflow-wrap: anywhere; }
.cm-err { border-left: 2px solid var(--offline); background: color-mix(in srgb, var(--offline) 14%, transparent); }
.cm-ok { border-left: 2px solid var(--online); background: color-mix(in srgb, var(--online) 12%, transparent); }

/* ------------------------------------------------------------------ the clan */

.cm-clan { display: flex; flex-direction: column; gap: 12px; }
.cm-card { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.cm-card .clan-tag { min-width: 64px; height: 64px; line-height: 62px; font-size: 20px; }
.cm-clan-name { font-size: clamp(24px, 3vw, 34px); }
.cm-desc { margin: 0; display: block; -webkit-line-clamp: unset; line-clamp: none; max-width: 70ch; }
.cm-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cm-colour { display: flex; align-items: center; gap: 8px; }
.cm-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.cm-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Roster: one grid for the whole list, every row on it (subgrid), so the columns line up down the
   list: the name (cut with an ellipsis; the full name is its title), You, the role badge (all the
   same width), then for leaders Make/Remove co-leader and Kick, each in its own column. */
.cm-members {
    margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--panel-line);
    display: grid; grid-template-columns: minmax(0, 1fr) max-content max-content; column-gap: 10px;
}
.cm-members.is-lead { grid-template-columns: minmax(0, 1fr) max-content max-content max-content max-content; }
.cm-member {
    grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: center; row-gap: 10px;
    min-height: 58px; padding: 10px 0; border-bottom: 1px solid var(--panel-line);
}
@supports not (grid-template-columns: subgrid) {
    .cm-member { grid-template-columns: minmax(0, 1fr) auto auto auto auto; column-gap: 10px; }
}
.cm-member.is-you { box-shadow: inset 2px 0 0 var(--accent); padding-left: 12px; }
.cm-mname { grid-column: 1; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; font-size: 15px; }
.cm-you { grid-column: 2; grid-row: 1; justify-self: end; padding: 4px 7px; background: var(--accent-tint); font-weight: 800; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text); }
.cm-role { font-weight: 800; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; text-align: center; }
.cm-member .cm-role { grid-column: 3; grid-row: 1; }
.cm-role.is-owner { border-color: var(--accent); }
.cm-role.is-member { color: var(--text-4); border-color: var(--line); }
.cm-mact { display: contents; }
.cm-mbtn { min-height: 34px; justify-content: center; grid-row: 1; }
.cm-mbtn[data-cm-act="promote"], .cm-mbtn[data-cm-act="demote"] { grid-column: 4; }
.cm-mbtn[data-cm-act="kick"] { grid-column: 5; }
.cm-page .btn.is-armed { border-color: var(--offline); background: color-mix(in srgb, var(--offline) 16%, transparent); color: var(--text); }

.cm-code { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.cm-code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; max-width: 100%; }
.cm-code-val {
    padding: 8px 14px; border: 1px solid var(--line-strong); background: color-mix(in srgb, var(--obsidian) 84%, var(--deep-peacock));
    font-family: var(--font-display); font-stretch: var(--display-stretch); font-weight: 900; font-size: 22px; letter-spacing: 0.08em;
    overflow-wrap: anywhere; user-select: all; -webkit-user-select: all;
}
.cm-facts {
    margin: 0; width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px;
    background: var(--panel-line); border: 1px solid var(--panel-line);
}
.cm-facts div { padding: 10px 14px; background: color-mix(in srgb, var(--obsidian) 84%, var(--deep-peacock)); min-width: 0; }
.cm-facts dt { font-weight: 800; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); overflow-wrap: anywhere; }
.cm-facts dd { margin: 4px 0 0; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cm-when { display: block; margin-top: 2px; font-weight: 600; font-size: 13px; color: var(--text-3); }
.cm-facts dd.is-expired { color: var(--text); text-decoration: line-through; text-decoration-color: var(--offline); }
.cm-invite-form { padding-top: 16px; border-top: 1px solid var(--panel-line); }
.cm-code + .cm-muted, .cm-muted + .cm-invite-form:not([hidden]) { margin-top: -4px; }
.cm-lead-tools { display: flex; flex-direction: column; gap: 10px; }

/* Owner tools: the accent line is red, the actions hard to undo. */
.cm-danger::before { background: var(--offline); }
.cm-sub { padding-top: 18px; border-top: 1px solid var(--panel-line); gap: 12px; }
.cm-disband-btn:not(:disabled) { border-color: var(--offline); color: var(--text); }

/* ------------------------------------------------------------------ segmented choices */

/* Max uses and Valid for: native radios (arrow keys move the choice) drawn as one row of segments,
   split by hairlines; the chosen one is lit teal with a bar under it. */
.cm-seg { display: grid; gap: 1px; border: 1px solid var(--line-strong); background: var(--line-strong); }
.cm-seg[data-count="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cm-seg[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cm-seg-opt { position: relative; display: flex; min-width: 0; }
.cm-seg-opt input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cm-seg-opt span {
    flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 8px;
    background: color-mix(in srgb, var(--obsidian) 88%, var(--deep-peacock)); cursor: pointer;
    font-weight: 800; font-size: 13px; line-height: 1.2; text-align: center; color: var(--text-3); overflow-wrap: anywhere;
}
.cm-seg-opt input:checked + span { background: color-mix(in srgb, var(--peacock-teal) 22%, var(--obsidian)); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.cm-seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.cm-seg-opt:active span { background: color-mix(in srgb, var(--peacock-teal) 30%, var(--obsidian)); }

/* ------------------------------------------------------------------ the new-owner listbox */

.cm-pick-btn {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 10px 14px;
    border: 1px solid var(--line-strong); background-color: color-mix(in srgb, var(--obsidian) 80%, transparent);
    text-align: left; font-weight: 700; font-size: 16px; color: var(--text-3);
}
.cm-pick.has-value .cm-pick-btn { color: var(--text); }
.cm-pick-val { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-pick-btn .cm-role { flex: none; }
.cm-pick-caret { flex: none; color: var(--accent); transition: transform 0.15s; }
.cm-pick.is-open .cm-pick-caret { transform: rotate(180deg); }
.cm-pick.is-open .cm-pick-btn { border-color: var(--accent); }
.cm-pick-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.cm-pick-btn:active { background-color: var(--panel-hover); }
.cm-pick-list {
    margin: -8px 0 0; padding: 4px 0; list-style: none; max-height: 300px; overflow-y: auto; overscroll-behavior: contain;
    border: 1px solid var(--accent); border-top-color: var(--line-strong); background: color-mix(in srgb, var(--obsidian) 90%, var(--deep-peacock));
}
.cm-pick-list:focus { outline: none; }
.cm-pick-list:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.cm-pick-list [role="option"] { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 14px; cursor: pointer; }
.cm-pick-list [role="option"].is-active { background: var(--panel-hover); box-shadow: inset 2px 0 0 var(--accent); }
.cm-pick-list [role="option"][aria-selected="true"] { background: var(--accent-tint); }
.cm-pick-list [role="option"]:active { background: color-mix(in srgb, var(--peacock-teal) 22%, transparent); }
.cm-pick-list .cm-role, .cm-pick-btn .cm-role { min-width: 96px; }
.cm-opt-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; font-size: 15px; }

/* ------------------------------------------------------------------ button states */

/* Every button on the page answers: hover (only where there is a mouse, so phones never keep a
   stuck hover), a press on touch and click, and a clear keyboard focus ring. Primary buttons keep
   site.css's brighten; their slanted clip would cut an outer ring, so theirs is drawn inside. */
.cm-page .btn { transition: background-color 0.15s, border-color 0.15s, color 0.15s, filter 0.15s, transform 0.1s; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.cm-page .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cm-page .btn-primary:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: -5px; }
@media (hover: hover) {
    .cm-page .btn-outline:not(:disabled):hover { border-color: var(--accent); background-color: var(--accent-tint); color: var(--text); }
    .cm-page .btn-outline-accent:not(:disabled):hover { background-color: var(--accent-tint); color: var(--text); }
    .cm-page .btn-ghost:not(:disabled):hover { border-color: var(--accent); background-color: var(--surface-hover); }
    .cm-page .btn.is-armed:hover, .cm-page .cm-disband-btn:not(:disabled):hover { border-color: var(--offline); background-color: color-mix(in srgb, var(--offline) 24%, transparent); color: var(--text); }
    .cm-swatch:hover, .cm-pick-btn:hover { border-color: var(--accent); }
    .cm-seg-opt:hover input:not(:checked) + span { background: color-mix(in srgb, var(--peacock-teal) 10%, var(--obsidian)); color: var(--text); }
}
@media (hover: none) {
    .cm-page .btn-primary:hover { filter: none; }
}
.cm-page .btn:not(:disabled):active { transform: translateY(1px); }
.cm-page .btn-primary:not(:disabled):active { filter: brightness(0.9); }
.cm-page .btn-outline:not(:disabled):active, .cm-page .btn-outline-accent:not(:disabled):active, .cm-page .btn-ghost:not(:disabled):active {
    border-color: var(--accent); background-color: color-mix(in srgb, var(--peacock-teal) 20%, transparent); color: var(--text);
}
.cm-page .btn.is-armed:active, .cm-page .cm-disband-btn:not(:disabled):active { background-color: color-mix(in srgb, var(--offline) 32%, transparent); }
.cm-swatch:active { background: var(--panel-hover); }
@media (prefers-reduced-motion: reduce) {
    .cm-page .btn, .cm-pick-caret { transition: none; }
    .cm-page .btn:not(:disabled):active { transform: none; }
}
.cm-leave { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.cm-leave .cm-err { flex-basis: 100%; }

/* ------------------------------------------------------------------ narrower */

@media (max-width: 960px) {
    .cm-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
    .cm-split { grid-template-columns: minmax(0, 1fr); }
    .cm-join { order: -1; } /* most players arrive with a code */
}
@media (max-width: 620px) {
    .cm-signin { padding: 22px 18px; }
    .cm-signin-btn { width: 100%; justify-content: center; }
    .cm-box, .cm-card { padding: 18px 16px; }
    .cm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cm-home .cm-facts { grid-template-columns: minmax(0, 1fr); }
    /* Phones: name, You and role on one line; the actions under them, Kick always on the right half. */
    .cm-members.is-lead { grid-template-columns: minmax(0, 1fr) max-content max-content; }
    .cm-mact { display: grid; grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 8px; }
    .cm-mbtn[data-cm-act="promote"], .cm-mbtn[data-cm-act="demote"] { grid-column: 1; }
    .cm-mbtn[data-cm-act="kick"] { grid-column: 2; }
    .cm-mbtn { min-height: 44px; padding: 6px 10px; letter-spacing: 0.05em; }
    .cm-seg[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cm-pick-list [role="option"] { min-height: 52px; }
    .cm-submit { align-self: stretch; justify-content: center; }
    .cm-code-row .btn, .cm-code > .btn, .cm-btns .btn { flex: 1 1 auto; justify-content: center; }
    .cm-leave .btn { width: 100%; justify-content: center; }
    .page-head .link-accent { order: -1; }
}
