:root {
    --paper: #faf7ee;
    --ink: #26231d;
    --soft-ink: #6f685b;
    --line: rgba(38, 35, 29, 0.16);
    --red: #b84e34;
    --green: #567455;
    --blue: #3d6579;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.78), transparent 28rem),
        linear-gradient(90deg, rgba(38, 35, 29, 0.035) 1px, transparent 1px) 0 0 / 32px 32px,
        linear-gradient(0deg, rgba(38, 35, 29, 0.03) 1px, transparent 1px) 0 0 / 32px 32px,
        var(--paper);
    font-family: ui-serif, "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    opacity: 0;
    pointer-events: none;
}

body[data-special-effect]::before {
    animation: specialWash 2400ms ease both;
}

body[data-special-effect="festival"]::before {
    background:
        radial-gradient(circle at 20% 26%, rgba(184, 78, 52, 0.3), transparent 18rem),
        radial-gradient(circle at 78% 18%, rgba(246, 177, 54, 0.32), transparent 16rem);
}

body[data-special-effect="magic"]::before {
    background:
        conic-gradient(from 0.2turn at 50% 42%, rgba(184, 78, 52, 0.22), rgba(86, 116, 85, 0.2), rgba(61, 101, 121, 0.24), rgba(184, 78, 52, 0.22));
}

body[data-special-effect="digital"]::before {
    background:
        repeating-linear-gradient(0deg, rgba(61, 101, 121, 0.16) 0 2px, transparent 2px 10px),
        linear-gradient(90deg, rgba(38, 35, 29, 0.12), transparent 28%, rgba(86, 116, 85, 0.12));
}

body[data-special-effect="heroic"]::before {
    background:
        radial-gradient(circle at 50% 56%, rgba(184, 78, 52, 0.36), transparent 18rem),
        radial-gradient(circle at 58% 42%, rgba(246, 177, 54, 0.28), transparent 10rem);
}

body[data-special-effect="ghost"]::before {
    background:
        radial-gradient(circle at 50% 36%, rgba(90, 92, 103, 0.28), transparent 24rem),
        linear-gradient(180deg, rgba(38, 35, 29, 0.13), transparent 58%);
}

body[data-special-effect="time"]::before {
    background:
        repeating-conic-gradient(from 0.05turn at 50% 42%, rgba(61, 101, 121, 0.16) 0 8deg, transparent 8deg 24deg);
}

body[data-special-effect="unlock"]::before {
    background:
        radial-gradient(circle at 50% 46%, rgba(246, 177, 54, 0.38), transparent 12rem),
        radial-gradient(circle at 50% 46%, transparent 8rem, rgba(61, 101, 121, 0.16) 8.2rem, transparent 8.8rem);
}

body[data-special-effect="star"]::before,
body[data-special-effect="moon"]::before,
body[data-special-effect="dream"]::before {
    background:
        radial-gradient(circle at 34% 20%, rgba(255, 255, 255, 0.78) 0 2px, transparent 3px),
        radial-gradient(circle at 70% 28%, rgba(255, 255, 255, 0.72) 0 1px, transparent 2px),
        linear-gradient(180deg, rgba(61, 101, 121, 0.26), transparent 68%);
}

body[data-special-effect="sea"]::before {
    background:
        radial-gradient(ellipse at 50% 86%, rgba(61, 101, 121, 0.28), transparent 24rem),
        repeating-linear-gradient(0deg, rgba(61, 101, 121, 0.1) 0 3px, transparent 3px 16px);
}

body[data-special-effect="snow"]::before {
    background:
        radial-gradient(circle at 50% 24%, rgba(255, 255, 255, 0.88), transparent 20rem),
        linear-gradient(180deg, rgba(61, 101, 121, 0.16), transparent 70%);
}

body[data-special-effect="rain"]::before,
body[data-special-effect="tears"]::before {
    background:
        repeating-linear-gradient(100deg, rgba(61, 101, 121, 0.16) 0 1px, transparent 1px 18px),
        linear-gradient(180deg, rgba(61, 101, 121, 0.16), transparent 74%);
}

body[data-special-effect="paper"]::before,
body[data-special-effect="promise"]::before {
    background:
        radial-gradient(circle at 50% 44%, rgba(184, 78, 52, 0.18), transparent 18rem),
        radial-gradient(circle at 62% 36%, rgba(86, 116, 85, 0.16), transparent 14rem);
}

button,
input,
select {
    font: inherit;
}

.stage {
    position: relative;
    z-index: 1;
    width: min(920px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 14vh 0 56px;
    display: grid;
    justify-items: center;
    align-content: start;
}

.current-theme {
    width: 100%;
    min-height: 38vh;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 26px;
    text-align: center;
}

h1 {
    width: min(100%, 820px);
    margin: 0;
    font-size: clamp(2.15rem, 7.8vw, 5.8rem);
    font-weight: 500;
    line-height: 1.48;
    letter-spacing: 0;
    overflow-wrap: anywhere;
    text-wrap: balance;
    min-height: 3.1em;
}

.flowing {
    animation: flowingText 2200ms cubic-bezier(0.2, 0.72, 0.16, 1) both;
}

.special-prompt {
    animation: specialPrompt 2200ms cubic-bezier(0.2, 0.72, 0.16, 1) both;
}

.typing {
    animation: none;
}

.ime-composing {
    position: relative;
    color: var(--ink);
    text-decoration-line: underline;
    text-decoration-color: rgba(61, 101, 121, 0.72);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.16em;
}

.ime-composing::after {
    content: "";
    position: absolute;
    inset: 0.08em -0.05em 0.02em;
    background: rgba(61, 101, 121, 0.08);
    z-index: -1;
}

.ime-commit {
    animation: commitFlash 260ms ease both;
}

.caret {
    display: inline-block;
    width: 0.08em;
    height: 1.08em;
    margin-left: 0.05em;
    border-radius: 999px;
    background: var(--red);
    transform: translateY(0.16em);
    animation: caretBlink 760ms steps(2, jump-none) infinite;
}

.gacha-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 190px;
    min-height: 58px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    padding: 0 26px;
    background: var(--ink);
    color: var(--paper);
    cursor: pointer;
    box-shadow: 0 14px 34px rgba(38, 35, 29, 0.18);
    transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 800;
}

.gacha-button:hover {
    transform: translateY(-2px);
    background: #383126;
    box-shadow: 0 18px 42px rgba(38, 35, 29, 0.22);
}

.gacha-button:active {
    transform: translateY(0);
}

.gacha-button:focus-visible {
    outline: 3px solid rgba(61, 101, 121, 0.28);
    outline-offset: 4px;
}

.button-mark {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-radius: 50%;
    box-shadow:
        inset 0 0 0 3px var(--ink),
        inset 0 0 0 7px currentColor;
}

.gacha-button:hover .button-mark {
    animation: turn 820ms ease;
}

.gacha-button.is-typing .button-mark {
    animation: turn 1080ms ease-in-out infinite;
}

.gacha-button.special-button {
    animation: specialButton 640ms ease both;
}

.special-effect-layer {
    position: fixed;
    inset: 0;
    z-index: 10;
    overflow: hidden;
    pointer-events: none;
}

.special-particle {
    position: absolute;
    left: 0;
    top: 0;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    font-size: var(--size);
    line-height: 1;
    opacity: 0;
    filter: drop-shadow(0 6px 12px rgba(38, 35, 29, 0.16));
    transform: translate3d(var(--x), var(--y), 0) scale(0.72) rotate(0deg);
    animation: particleBurst var(--duration) cubic-bezier(0.2, 0.72, 0.16, 1) var(--delay) both;
    will-change: transform, opacity;
}

.word-panel {
    width: min(100%, 640px);
    margin-top: 28px;
    opacity: 0;
    transform: translateY(-10px);
}

.word-panel[hidden] {
    display: none;
}

.word-panel.is-revealed {
    animation: panelReveal 760ms cubic-bezier(0.2, 0.72, 0.16, 1) both;
}

.word-form {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(136px, 0.36fr) 48px;
    gap: 8px;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.word-form input,
.word-form select,
.word-button {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(250, 247, 238, 0.72);
    color: var(--ink);
    outline: none;
}

.word-form input {
    min-width: 0;
    padding: 0 18px;
}

.word-form select {
    padding: 0 14px;
    cursor: pointer;
}

.word-button {
    display: inline-grid;
    place-items: center;
    padding: 0;
    color: var(--paper);
    background: var(--blue);
    border-color: transparent;
    cursor: pointer;
    font-size: 1.16rem;
    font-weight: 800;
}

.word-form input:focus,
.word-form select:focus,
.word-button:focus-visible {
    border-color: rgba(61, 101, 121, 0.64);
    box-shadow: 0 0 0 3px rgba(61, 101, 121, 0.14);
}

.word-button:hover {
    background: #315365;
}

.word-status {
    min-height: 1.5em;
    margin: 10px 0 0;
    color: var(--soft-ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.86rem;
}

.custom-word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.custom-word-list:empty {
    display: none;
}

.custom-word-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 100%;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 6px 0 12px;
    background: rgba(250, 247, 238, 0.8);
    color: var(--soft-ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.82rem;
}

.custom-word-chip span {
    overflow-wrap: anywhere;
}

.custom-word-chip button {
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    padding: 0;
    background: rgba(38, 35, 29, 0.08);
    color: var(--soft-ink);
    cursor: pointer;
    line-height: 1;
}

.custom-word-chip button:hover,
.custom-word-chip button:focus-visible {
    background: var(--red);
    color: var(--paper);
    outline: none;
}

.history-list {
    width: min(100%, 720px);
    margin: 34px 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0;
    border-top: 1px solid var(--line);
}

.history-list li {
    position: relative;
    padding: 18px 6px 18px 58px;
    border-bottom: 1px solid var(--line);
    color: var(--soft-ink);
    font-size: clamp(1rem, 2.2vw, 1.22rem);
    line-height: 1.8;
    overflow-wrap: anywhere;
    animation: historyIn 900ms ease both;
}

.history-list li::before {
    content: "";
    position: absolute;
    left: 10px;
    top: 29px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 16px 0 0 var(--green), 32px 0 0 var(--blue);
    transform: scale(0.74);
    opacity: 0.8;
}

@keyframes flowingText {
    0% {
        opacity: 0;
        filter: blur(8px);
        transform: translateX(30px);
    }

    42% {
        opacity: 1;
        filter: blur(0);
    }

    100% {
        opacity: 1;
        filter: blur(0);
        transform: translateX(0);
    }
}

@keyframes caretBlink {

    0%,
    48% {
        opacity: 1;
    }

    49%,
    100% {
        opacity: 0;
    }
}

@keyframes commitFlash {
    0% {
        background: rgba(184, 78, 52, 0.24);
        color: var(--ink);
    }

    100% {
        background: transparent;
        color: inherit;
    }
}

@keyframes specialWash {
    0% {
        opacity: 0;
        transform: scale(1);
    }

    18%,
    58% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: scale(1.08);
    }
}

@keyframes specialPrompt {
    0% {
        filter: blur(0);
        text-shadow: none;
        transform: translateY(0);
    }

    22% {
        filter: blur(0);
        text-shadow:
            0 0 22px rgba(255, 255, 255, 0.8),
            0 14px 34px rgba(61, 101, 121, 0.24);
        transform: translateY(-2px);
    }

    46% {
        filter: blur(0.5px);
    }

    100% {
        filter: blur(0);
        text-shadow: none;
        transform: translateY(0);
    }
}

@keyframes specialButton {
    0%,
    100% {
        transform: translateX(0);
    }

    18% {
        transform: translateX(-5px) rotate(-1deg);
    }

    36% {
        transform: translateX(5px) rotate(1deg);
    }

    54% {
        transform: translateX(-3px) rotate(-0.7deg);
    }

    72% {
        transform: translateX(3px) rotate(0.7deg);
    }
}

@keyframes particleBurst {
    0% {
        opacity: 0;
        transform: translate3d(var(--x), var(--y), 0) scale(0.58) rotate(0deg);
    }

    12% {
        opacity: 1;
    }

    72% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate3d(calc(var(--x) + var(--dx)), calc(var(--y) + var(--dy)), 0) scale(1.18) rotate(var(--rot));
    }
}

@keyframes historyIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes panelReveal {
    from {
        opacity: 0;
        filter: blur(6px);
        transform: translateY(-12px);
    }

    to {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0);
    }
}

@keyframes turn {
    to {
        transform: rotate(1turn);
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        transition-duration: 1ms !important;
    }

    body[data-special-effect]::before {
        animation: specialWash 1200ms ease both;
    }

    .special-particle {
        display: none;
    }

    .special-prompt,
    .gacha-button.special-button {
        animation-duration: 1ms !important;
    }
}

@media (max-width: 560px) {
    .stage {
        width: min(100% - 22px, 460px);
        padding-top: 10vh;
    }

    .current-theme {
        min-height: 44vh;
    }

    .history-list {
        margin-top: 42px;
    }

    .word-form {
        grid-template-columns: 1fr 48px;
    }

    .word-form select {
        grid-column: 1 / -1;
        grid-row: 2;
    }
}
