:root {
    --bg: #090b14;
    --panel: #131827;
    --panel-2: #1b2337;
    --text: #f5f7fb;
    --muted: #aab6d4;
    --accent: #75f4ff;
    --accent-2: #ffe66d;
    --danger: #ff6b8a;
    --success: #7cff9b;
    --beam: #f8f0c8;
    --metal: #c9d8ff;
    --shadow: rgba(0, 0, 0, 0.45);
    --tilt: 0deg;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, rgba(117, 244, 255, 0.16), transparent 28rem),
    radial-gradient(circle at top right, rgba(255, 230, 109, 0.12), transparent 24rem),
    var(--bg);
    color: var(--text);
}

button,
select,
input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 0.9rem;
    padding: 0.72rem 0.9rem;
    background: #26324f;
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 0.45rem 1rem var(--shadow);
    transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover {
    transform: translateY(-1px);
    background: #324164;
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 0.25rem 0.7rem var(--shadow);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.primary-button {
    background: linear-gradient(135deg, #00d4ff, #7c5cff);
    color: white;
    font-weight: 800;
}

.secondary-button,
.small-button {
    background: #202a43;
}

.small-button {
    padding: 0.45rem 0.7rem;
    font-size: 0.86rem;
}

.wide-button {
    width: 100%;
    margin-top: 0.65rem;
}

.app-header {
    width: min(1240px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 1.2rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: stretch;
}

.eyebrow {
    margin: 0 0 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--accent);
    font-weight: 800;
    font-size: 0.78rem;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.45rem;
    font-size: clamp(2rem, 5vw, 4.6rem);
    line-height: 0.95;
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 0.9rem;
}

h3 {
    font-size: 1rem;
    margin-bottom: 0.4rem;
}

h4 {
    margin-bottom: 0.55rem;
    color: var(--accent-2);
}

.subtitle,
.hint,
.feedback,
#weightReadout {
    color: var(--muted);
}

.subtitle {
    max-width: 58rem;
    margin-bottom: 0;
}

.header-card,
.panel,
.history-section,
.final-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
    border: 1px solid rgba(255, 255, 255, 0.11);
    box-shadow: 0 1rem 3rem var(--shadow);
    backdrop-filter: blur(10px);
}

.header-card {
    min-width: 170px;
    border-radius: 1.25rem;
    padding: 1rem;
    display: grid;
    align-content: center;
    gap: 0.55rem;
    text-align: center;
}

.header-card strong {
    display: block;
    font-size: 2rem;
    color: var(--accent-2);
}

.label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 800;
}

.layout {
    width: min(1240px, calc(100% - 2rem));
    margin: 0 auto;
    display: grid;
    grid-template-columns: 280px minmax(360px, 1fr) 340px;
    gap: 1rem;
    align-items: start;
}

.panel {
    border-radius: 1.5rem;
    padding: 1rem;
}

.field {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.field span {
    font-weight: 750;
    color: var(--text);
}

.inline-field {
    grid-template-columns: 1fr 84px;
    gap: 0.8rem;
    align-items: center;
}

select,
input {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.85rem;
    background: #0e1424;
    color: var(--text);
    padding: 0.72rem 0.8rem;
    outline: none;
}

select:focus,
input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(117, 244, 255, 0.16);
}

.setup-panel > button {
    width: 100%;
    margin-bottom: 0.65rem;
}

.equation-card,
.status-card,
.control-group {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.15rem;
    padding: 0.9rem;
    margin-top: 0.85rem;
}

.equation {
    font-size: clamp(1.45rem, 4vw, 2.1rem);
    color: var(--accent-2);
    font-weight: 900;
    margin-top: 0.4rem;
    word-break: break-word;
}

.status-card {
    display: flex;
    gap: 0.85rem;
    align-items: center;
}

.status-dot {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--success);
    box-shadow: 0 0 18px var(--success);
}

.status-card.unbalanced .status-dot {
    background: var(--danger);
    box-shadow: 0 0 18px var(--danger);
}

.status-card p {
    margin-bottom: 0;
    font-size: 0.88rem;
}

.scale-stage {
    min-height: 640px;
    border-radius: 1.8rem;
    padding: 1rem;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(117, 244, 255, 0.09), rgba(255, 230, 109, 0.035)),
    rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stage-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
}

.stage-heading p {
    max-width: 24rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.scale-wrap {
    position: relative;
    height: 510px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1.2rem;
}

.scale-beam {
    --tilt: 0deg;
    position: absolute;
    top: 150px;
    left: 50%;
    width: min(720px, 96%);
    height: 26px;
    transform: translateX(-50%) rotate(var(--tilt));
    transform-origin: center;
    border-radius: 999px;
    background: linear-gradient(180deg, #fff7d4, #cbbf86);
    box-shadow: 0 0 18px rgba(255, 230, 109, 0.35), 0 0.9rem 1.4rem var(--shadow);
    transition: transform 500ms cubic-bezier(.2, .9, .2, 1);
}

.scale-beam::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -18px;
    transform: translateX(-50%);
    width: 22px;
    height: 62px;
    border-radius: 12px;
    background: var(--metal);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.2);
}

/*.pan {
  position: absolute;
  top: 32px;
  width: min(280px, 38vw);
  min-height: 185px;
  border-radius: 0 0 2rem 2rem;
  background: linear-gradient(180deg, rgba(117, 244, 255, 0.25), rgba(117, 244, 255, 0.08));
  border: 3px solid var(--accent);
  box-shadow: 0 0 28px rgba(117, 244, 255, 0.24), 0 1rem 1.5rem var(--shadow);
  padding: 2rem 0.65rem 0.7rem;
  transform: rotate(calc(-1 * var(--tilt)));
  transition: transform 500ms cubic-bezier(.2,.9,.2,1);
}*/

.pan {
    position: absolute;
    top: 32px;
    width: min(260px, 34vw);
    min-height: 170px;
    border-radius: 0 0 2rem 2rem;
    background: linear-gradient(180deg, rgba(117, 244, 255, 0.25), rgba(117, 244, 255, 0.08));
    border: 3px solid var(--accent);
    box-shadow: 0 0 28px rgba(117, 244, 255, 0.24), 0 1rem 1.5rem var(--shadow);
    padding: 1.85rem 0.55rem 0.65rem;
    transform: rotate(calc(-1 * var(--tilt)));
    transition: transform 500ms cubic-bezier(.2, .9, .2, 1);
}

.pan::before,
.pan::after {
    content: "";
    position: absolute;
    top: -72px;
    width: 3px;
    height: 82px;
    background: var(--metal);
    transform-origin: bottom;
}

.pan::before {
    left: 18%;
    transform: rotate(-17deg);
}

.pan::after {
    right: 18%;
    transform: rotate(17deg);
}

.left-pan {
    left: 0;
    transform-origin: top center;
}

.right-pan {
    right: 0;
    transform-origin: top center;
}

.pan-label {
    position: absolute;
    left: 50%;
    top: 0.45rem;
    transform: translateX(-50%);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text);
    font-weight: 900;
    white-space: nowrap;
}

/*.items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 0.45rem;
  min-height: 130px;
}*/

.items {
    display: grid;
    grid-template-columns: repeat(5, max-content);
    justify-content: center;
    align-content: flex-start;
    gap: 0.4rem;
    min-height: 120px;
}

.fulcrum {
    position: absolute;
    top: 188px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 55px solid transparent;
    border-right: 55px solid transparent;
    border-bottom: 220px solid #c9d8ff;
    filter: drop-shadow(0 1rem 1rem var(--shadow));
}

.base {
    position: absolute;
    top: 410px;
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    height: 28px;
    border-radius: 999px;
    background: linear-gradient(180deg, #eef4ff, #94a8d4);
    box-shadow: 0 0 24px rgba(201, 216, 255, 0.28);
}

.gummy {
    width: 30px;
    height: 39px;
    position: relative;
    border-radius: 15px 15px 12px 12px;
    background: linear-gradient(160deg, #ff5c8a, #ffbd3f);
    box-shadow: inset -5px -7px 0 rgba(0, 0, 0, 0.12), 0 0 12px rgba(255, 110, 140, 0.45);
}

.gummy::before,
.gummy::after {
    content: "";
    position: absolute;
    top: -5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: inherit;
}

.gummy::before {
    left: 2px;
}

.gummy::after {
    right: 2px;
}

.gummy span::before,
.gummy span::after {
    content: "";
    position: absolute;
    top: 11px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #1b1020;
}

.gummy span::before {
    left: 9px;
}

.gummy span::after {
    right: 9px;
}

.x-box {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #09101d;
    font-size: 1.25rem;
    font-weight: 1000;
    background: linear-gradient(135deg, #75f4ff, #d8fff7);
    border: 3px solid white;
    box-shadow: 0 0 22px rgba(117, 244, 255, 0.42), inset 0 -8px 0 rgba(0, 0, 0, 0.08);
    transform: rotate(-4deg);
}

.x-box:nth-child(even) {
    transform: rotate(5deg);
}

.control-group:first-of-type {
    margin-top: 0;
}

.side-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.mini-panel {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    padding: 0.7rem;
}

.mini-panel button,
.button-grid button {
    width: 100%;
    margin-bottom: 0.45rem;
    padding: 0.62rem 0.55rem;
    font-size: 0.9rem;
}

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.button-grid button {
    margin-bottom: 0;
}

.feedback {
    margin: 0.8rem 0 0;
    line-height: 1.45;
}

.feedback.good {
    color: var(--success);
}

.feedback.warn {
    color: var(--accent-2);
}

.feedback.bad {
    color: var(--danger);
}

.final-card {
    margin: 0 auto;
    max-width: 380px;
    border-radius: 1.25rem;
    padding: 1rem;
    text-align: center;
    border-color: rgba(124, 255, 155, 0.35);
}

.final-card strong {
    color: var(--success);
    font-size: 1.05rem;
}

.final-card p {
    margin: 0.35rem 0 0;
    color: var(--accent-2);
    font-size: 2rem;
    font-weight: 1000;
}

.hidden {
    display: none;
}

.history-section {
    width: min(1240px, calc(100% - 2rem));
    margin: 1rem auto 2rem;
    border-radius: 1.5rem;
    padding: 1rem;
}

.history-section ol {
    margin: 0;
    padding-left: 1.5rem;
    color: var(--muted);
}

.history-section li {
    margin: 0.25rem 0;
}

@media (max-width: 1080px) {
    .layout {
        grid-template-columns: 1fr;
    }

/*    .scale-stage {
        order: -1;
    }*/

    .app-header {
        flex-direction: column;
    }

    .header-card {
        text-align: left;
        grid-template-columns: 1fr auto auto;
        align-items: center;
    }
}

@media (max-width: 640px) {
    .scale-stage {
        min-height: 620px;
    }

    .scale-wrap {
        height: 500px;
    }

    .scale-beam {
        top: 130px;
        width: 96%;
    }

    .pan {
        width: 42vw;
        min-height: 230px;
    }

    .items {
        gap: 0.32rem;
    }

    .gummy {
        width: 24px;
        height: 32px;
    }

    .x-box {
        width: 42px;
        height: 42px;
    }

    .fulcrum {
        top: 175px;
    }

    .base {
        top: 398px;
        width: 220px;
    }

    .side-controls,
    .button-grid {
        grid-template-columns: 1fr;
    }
}
