/* Coin change (/coin-change): the coin tray, the meter that fills up towards the amount, the counter with the coins
   used, and the coin list in the control panel. The table view uses css/apps/dp.css. Tiles, buttons, fields and the
   callout come from the app kit. Loaded only on its page (Views/SeoLanding/_CoinChangeDemo.cshtml,
   filter-engines/coin-change.js). */

.cc-app {
    /* The coins are an illustration: the same metals on both themes. */
    /* Flat metals: a face colour (-1) and a rim and stamp colour (-2). */
    --cc-copper-1: #e9935a;
    --cc-copper-2: #8a3b12;
    --cc-silver-1: #d6dce4;
    --cc-silver-2: #4b5563;
    --cc-gold-1: #fbbf24;
    --cc-gold-2: #92400e;
}

/* One view at a time (data-cc-current, set by the script). */
.cc-app[data-cc-current="coins"] [data-cc-view="table"],
.cc-app[data-cc-current="table"] [data-cc-view="coins"] {
    display: none !important;
}

.cc-app .cc-views { align-self: stretch; }

.cc-app .cc-say {
    min-height: 3.1rem;
    align-items: center;
}

.cc-app .cc-say > .ak-icon { align-self: flex-start; margin-top: 0.1rem; }

.cc-app .cc-say-body {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.6rem;
}

.cc-app .cc-say--success {
    border-color: color-mix(in srgb, var(--ak-success) 45%, var(--ak-border));
    background: color-mix(in srgb, var(--ak-success) 10%, var(--ak-panel));
}

.cc-app .cc-say--success > .ak-icon { color: var(--ak-success); }

.cc-app .cc-see-how {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ak-accent);
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.cc-app .cc-see-how:focus-visible {
    outline: 2px solid var(--ak-accent);
    outline-offset: 2px;
    border-radius: 3px;
}

.cc-app .cc-best-tile.is-found { --ak-stat-color: var(--ak-success) !important; }

/* ---- Coins ------------------------------------------------------------------------------------------------------- */

/* A coin: a flat disc in its metal with a crisp rim, an inner ring and the value stamped on it; --cc-s scales it
   (bigger values, bigger coins). No gradients or soft shadows: only solid fills and hard edges. */
.cc-app .cc-coin {
    --cc-s: 1;
    --cc-1: var(--cc-silver-1);
    --cc-2: var(--cc-silver-2);
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: calc(var(--cc-d, 4.6rem) * var(--cc-s));
    aspect-ratio: 1;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--cc-1);
    box-shadow: inset 0 0 0 calc(3px * var(--cc-s)) var(--cc-2), 0 3px 0 var(--cc-2);
    color: var(--cc-2);
    font: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.2s ease, filter 0.2s ease;
}

.cc-app .cc-coin--copper { --cc-1: var(--cc-copper-1); --cc-2: var(--cc-copper-2); }
.cc-app .cc-coin--gold { --cc-1: var(--cc-gold-1); --cc-2: var(--cc-gold-2); }

/* The inner ring, a thin line inside the rim. */
.cc-app .cc-coin::before {
    content: "";
    position: absolute;
    inset: calc(14% - 1px);
    border: calc(1.5px * var(--cc-s) + 0.5px) solid var(--cc-2);
    border-radius: 50%;
    opacity: 0.55;
    pointer-events: none;
}

.cc-app .cc-coin-face {
    position: relative;
    font-size: calc(1.15rem * var(--cc-s));
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.cc-app .cc-coin:hover { transform: translateY(-3px); }

.cc-app .cc-coin:focus-visible {
    outline: 3px solid var(--ak-accent);
    outline-offset: 3px;
}

.cc-app .cc-coin.is-too-big {
    opacity: 0.45;
    filter: grayscale(0.7);
    cursor: not-allowed;
}

.cc-app .cc-coin.is-too-big:hover { transform: none; }

.cc-app .cc-coin.cc-shake { animation: cc-shake 0.42s ease; }

@keyframes cc-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(3px); }
}

/* ---- Tray, meter and counter ------------------------------------------------------------------------------------- */

.cc-app .cc-scene {
    display: flex;
    flex-direction: column;
    gap: var(--ak-space-4);
}

.cc-app .cc-tray {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: var(--ak-space-4);
    margin: 0;
    padding: var(--ak-space-4) var(--ak-space-3) var(--ak-space-3);
    border-radius: var(--ak-radius);
    background: color-mix(in srgb, #7c2d12 14%, var(--ak-panel));
    list-style: none;
}

.cc-app .cc-tray-slot { display: flex; }

.cc-app .cc-tray .cc-coin { --cc-d: 5rem; }

.cc-app .cc-goal {
    display: flex;
    align-items: center;
    gap: var(--ak-space-3);
}

.cc-app .cc-meter {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    gap: 2px;
    height: 2.75rem;
    padding: 3px;
    border: 2px solid var(--ak-border);
    border-radius: 999px;
    background: var(--ak-field);
    overflow: hidden;
}

.cc-app .cc-meter.is-made { border-color: var(--ak-success); }

.cc-app .cc-seg,
.cc-app .cc-seg-left {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 0.8rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cc-app .cc-seg {
    --cc-1: var(--cc-silver-1);
    --cc-2: var(--cc-silver-2);
    border-radius: 999px;
    background: var(--cc-1);
    box-shadow: inset 0 0 0 2px var(--cc-2);
    color: var(--cc-2);
}

.cc-app .cc-seg--copper { --cc-1: var(--cc-copper-1); --cc-2: var(--cc-copper-2); }
.cc-app .cc-seg--gold { --cc-1: var(--cc-gold-1); --cc-2: var(--cc-gold-2); }

.cc-app .cc-seg--new { animation: cc-grow 0.3s ease-out; }

@keyframes cc-grow {
    from { opacity: 0; transform: scaleX(0.3); }
    to { opacity: 1; transform: scaleX(1); }
}

.cc-app .cc-seg-left {
    border: 2px dashed color-mix(in srgb, var(--ak-muted) 45%, transparent);
    border-radius: 999px;
    color: var(--ak-muted);
}

/* The amount to make, as a price tag at the end of the meter. */
.cc-app .cc-target {
    flex: none;
    padding: 0.35rem 0.7rem;
    border-radius: 0.5rem;
    background: var(--ak-text);
    color: var(--ak-panel);
    font-size: 1.15rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cc-app .cc-counter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ak-space-2);
    min-height: 4.4rem;
    padding: var(--ak-space-3);
    border: 2px dashed var(--ak-border);
    border-radius: var(--ak-radius);
}

.cc-app .cc-counter .cc-coin { --cc-d: 3.4rem; }

/* Small coins keep the rim but not the inner ring, which would crowd the value. */
.cc-app .cc-counter .cc-coin::before { display: none; }

.cc-app .cc-coin--new { animation: cc-drop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.3); }

@keyframes cc-drop {
    from { opacity: 0; transform: translateY(-60%) scale(0.8); }
    to { opacity: 1; transform: none; }
}

.cc-app .cc-counter-empty {
    margin: auto;
    color: var(--ak-muted);
    font-size: var(--ak-fs-sm);
}

.cc-app .cc-problem { margin: 0; }

.cc-app.cc-is-solving .cc-tray .cc-coin,
.cc-app.cc-is-solving .cc-counter .cc-coin { pointer-events: none; }

@media (max-width: 560px) {
    .cc-app .cc-tray .cc-coin { --cc-d: 4rem; }
    .cc-app .cc-counter .cc-coin { --cc-d: 2.8rem; }
}

@media (prefers-reduced-motion: reduce) {
    .cc-app .cc-coin,
    .cc-app .cc-coin--new,
    .cc-app .cc-seg--new,
    .cc-app .cc-coin.cc-shake { transition: none; animation: none; }
}

/* ---- Coin list in the control panel ------------------------------------------------------------------------------ */

.cc-app .cc-item-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0.15rem 0 0.5rem;
    padding: 0;
    list-style: none;
}

.cc-app .cc-item {
    display: grid;
    grid-template-columns: 1.6rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.4rem;
}

.cc-app .cc-item-coin {
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: var(--cc-gold-1);
    box-shadow: inset 0 0 0 2px var(--cc-gold-2);
    color: var(--cc-gold-2);
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1.6rem;
    text-align: center;
}

.cc-app .cc-item-affix .cc-unit {
    position: absolute;
    inset-inline-end: 0.6rem;
    color: var(--ak-muted);
    font-size: var(--ak-fs-sm);
    pointer-events: none;
}

.cc-app .cc-item-affix > input.ak-field.cc-item-field:not([type="range"]) {
    width: 100%;
    min-width: 0;
    padding-inline-end: 1.8rem;
}

.cc-app .cc-add {
    justify-self: start;
    align-self: flex-start;
}
