*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    background: #111;
    color: #f5f5f5;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

button,
input {
    font: inherit;
    user-select: none;
    -webkit-user-select: none;
}

input[type="range"],
input[type="color"] {
    touch-action: manipulation;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    width: 100vw;
}

.top-bar {
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.top-bar__meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 3vw 0.15rem;
}

.app-name {
    margin: 0;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    opacity: 0.72;
}

.program-fps {
    margin: 0;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    opacity: 0.72;
    color: #9be7ff;
    white-space: nowrap;
}

.rpm-bar {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 3vw 0.45rem;
    flex-shrink: 0;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

.rpm-bar__label,
.rpm-bar__value {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.rpm-bar__value {
    min-width: 2.5rem;
    text-align: right;
    color: #9be7ff;
}

.rpm-bar__slider,
.size-control input[type="range"] {
    width: 100%;
    accent-color: #4dabf7;
}

.fps-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

.fps-toggle__label {
    line-height: 1;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.8;
}

.fps-toggle__label::before {
    content: "FPS";
}

.fps-options {
    display: flex;
    gap: 0.35rem;
}

.fps-btn {
    width: 2rem;
    height: 2rem;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    padding: 0;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.fps-btn.is-active,
.fps-btn[aria-pressed="true"] {
    background: #4dabf7;
    border-color: #4dabf7;
    color: #081018;
    transform: scale(1.06);
}

.disc-area {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 3vw;
    touch-action: none;
    cursor: crosshair;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

.disc-frame {
    width: min(calc(100vw - 6vw), 100%);
    aspect-ratio: 1;
    max-height: 100%;
    border-radius: 50%;
    overflow: hidden;
    background: #1a1a1a;
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, 0.08),
        0 12px 40px rgba(0, 0, 0, 0.45);
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

#disc {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

.controls {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 3vw calc(0.65rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.35);
}

.controls-part {
    padding: 0.55rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.controls-part:last-child {
    border-bottom: 0;
}

.controls-part__title {
    margin: 0 0 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.72;
}

.controls-part__body {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.controls-part__body--brush {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
}

.controls-part__body--control {
    justify-content: flex-start;
}

.controls-part__row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.controls-part__row--colors {
    justify-content: space-between;
}

.controls-part__row--tools {
    width: 100%;
}

.bg-swatches {
    display: flex;
    gap: 0.45rem;
    flex: 1;
}

.bg-swatch {
    width: 2rem;
    height: 2rem;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 0;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.bg-swatch.is-active {
    border-color: #fff;
    transform: scale(1.06);
}

.swatches {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 0.35rem;
    flex: 1;
}

.swatch {
    aspect-ratio: 1;
    width: 100%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    padding: 0;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.swatch.is-active {
    border-color: #fff;
    transform: scale(1.08);
}

.color-picker-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    min-width: 3.2rem;
}

.color-picker-wrap input[type="color"] {
    width: 2.4rem;
    height: 2.4rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.color-picker-wrap.is-active input[type="color"] {
    border-color: #fff;
    transform: scale(1.08);
}

.color-picker-wrap__label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.75;
}

.tool-group {
    display: inline-flex;
    gap: 0.35rem;
}

.tool-btn,
.history-btn {
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
    border-radius: 999px;
    padding: 0.45rem 0.75rem;
    cursor: pointer;
}

.tool-btn.is-active,
.tool-btn[aria-pressed="true"] {
    background: #4dabf7;
    border-color: #4dabf7;
    color: #081018;
}

.tool-btn--erase[aria-pressed="true"] {
    background: #ff6b6b;
    border-color: #ff6b6b;
    color: #1a0505;
}

.history-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.history-btn--muted {
    opacity: 0.85;
}

.size-control {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex: 1;
    min-width: 9rem;
}

.size-control__label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    white-space: nowrap;
}

.size-control output {
    min-width: 2.8rem;
    font-size: 0.8rem;
    color: #9be7ff;
}

@media (max-width: 420px) {
    .tool-btn,
    .history-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .swatches {
        gap: 0.25rem;
    }
}
