* {
    box-sizing: border-box;
}

:root {
    --cream: #fff4dc;
    --cream-deep: #f3dfb8;
    --chalk: #315f44;
    --chalk-soft: #6c9b60;
    --wood: #b77a45;
    --wood-dark: #7c4a2b;
    --paper: #fff9ed;
    --ink: #3b2a1d;
    --muted: #846f5a;
    --line: rgba(126, 88, 47, 0.18);
    --yellow: #f7d873;
    --shadow: 0 22px 55px rgba(86, 57, 24, 0.18);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.84), transparent 22rem),
        linear-gradient(180deg, #fff8e9, var(--cream));
    font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.site-header,
.pinball-app {
    width: min(1160px, calc(100% - 24px));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 14px 0;
    backdrop-filter: blur(18px);
}

.site-header::before {
    position: fixed;
    inset: 0 0 auto;
    z-index: -1;
    height: 68px;
    content: "";
    background: rgba(255, 248, 233, 0.88);
    border-bottom: 1px solid rgba(126, 88, 47, 0.14);
}

.brand,
.site-nav {
    display: inline-flex;
    align-items: center;
}

.brand {
    gap: 0.75rem;
    font-weight: 900;
    white-space: nowrap;
}

.brand-mark {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    color: #fffdf7;
    background: var(--chalk);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(49, 95, 68, 0.18);
}

.brand-name {
    font-size: 1.02rem;
}

.site-nav {
    gap: 0.2rem;
    padding: 5px;
    color: var(--muted);
    background: rgba(255, 249, 237, 0.82);
    border: 1px solid var(--line);
    border-radius: 999px;
}

.site-nav a {
    padding: 0.62rem 0.78rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 800;
    white-space: nowrap;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.site-nav a[aria-current="page"] {
    color: #fffdf7;
    background: var(--chalk);
    outline: 0;
}

.pinball-app {
    padding: clamp(1rem, 3vw, 2rem) 0;
}

.tool-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.eyebrow {
    margin: 0 0 0.7rem;
    color: var(--chalk-soft);
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 0.65rem;
    font-size: clamp(2.2rem, 7vw, 4.4rem);
    line-height: 1;
}

h2 {
    margin-bottom: 0;
    font-size: 1.1rem;
}

.tool-header p:last-child,
.hint {
    color: var(--muted);
    line-height: 1.6;
}

.tool-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 1rem;
    align-items: start;
}

.machine-card,
.panel-card,
.winner-card {
    background: rgba(255, 249, 237, 0.9);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.machine-card {
    overflow: hidden;
    padding: clamp(0.6rem, 2vw, 1rem);
}

#pinballCanvas {
    display: block;
    width: 100%;
    height: auto;
    min-height: 620px;
    background: var(--chalk);
    border-radius: 6px;
}

.winner-card {
    display: grid;
    min-width: min(100%, 270px);
    gap: 0.35rem;
    padding: 1rem;
}

.winner-card span,
label,
.stat-row span {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 800;
}

.winner-card strong {
    color: var(--wood-dark);
    font-size: clamp(1.5rem, 4vw, 2.3rem);
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.control-panel {
    display: grid;
    gap: 1rem;
}

.panel-card {
    display: grid;
    gap: 0.8rem;
    padding: 1rem;
}

textarea {
    width: 100%;
    min-height: 220px;
    resize: vertical;
    padding: 0.85rem;
    color: var(--ink);
    background: #fffdf7;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    line-height: 1.55;
}

textarea:focus {
    border-color: rgba(108, 155, 96, 0.68);
    box-shadow: 0 0 0 4px rgba(108, 155, 96, 0.12);
}

code {
    color: var(--chalk);
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    background: rgba(255, 255, 255, 0.46);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.switch-control {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ink);
}

.switch-control input {
    width: 18px;
    height: 18px;
    accent-color: var(--chalk-soft);
}

#duplicateModeText {
    color: var(--wood-dark);
    font-size: 0.82rem;
    font-weight: 900;
    white-space: nowrap;
}

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

.button {
    min-height: 48px;
    padding: 0.85rem 1rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 900;
}

.button.primary {
    color: #fffdf7;
    background: var(--chalk-soft);
    box-shadow: 0 6px 0 #4f7748;
}

.button.ghost {
    color: var(--ink);
    background: #fffdf7;
    border-color: var(--line);
}

.button:disabled {
    cursor: wait;
    opacity: 0.62;
}

.compact {
    gap: 0.55rem;
}

.stat-row,
.history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.stat-row strong {
    font-size: 1.55rem;
}

.text-button {
    padding: 0;
    color: var(--chalk);
    background: transparent;
    border: 0;
    font-size: 0.86rem;
    font-weight: 900;
}

.history-list {
    display: grid;
    max-height: 170px;
    gap: 0.45rem;
    overflow: auto;
    margin: 0;
    padding-left: 1.35rem;
    color: var(--muted);
    line-height: 1.45;
}

.history-list strong {
    color: var(--ink);
}

@media (max-width: 880px) {
    .site-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .site-header::before {
        height: 120px;
    }

    .site-nav {
        width: 100%;
        overflow-x: auto;
    }

    .tool-header,
    .tool-layout {
        grid-template-columns: 1fr;
    }

    .tool-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .winner-card {
        width: 100%;
    }

    .control-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .panel-card:first-child,
    .panel-card:last-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 560px) {
    .control-panel {
        grid-template-columns: 1fr;
    }

    .panel-card:first-child,
    .panel-card:last-child {
        grid-column: auto;
    }

    #pinballCanvas {
        min-height: 520px;
    }
}
