@font-face {
    font-family: "Jalnan2";
    src: url("/assets/Jalnan2TTF.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #f1e5cf;
    --bg-strong: #e3c39a;
    --paper: #fff9ef;
    --paper-deep: #f8ecd9;
    --ink: #1f1a15;
    --muted: #6f6257;
    --line: rgba(31, 26, 21, 0.12);
    --red: #a43026;
    --red-deep: #7d221b;
    --gold: #d39a2f;
    --gold-soft: #f4d08a;
    --green: #335d43;
    --shadow: 0 22px 48px rgba(72, 41, 14, 0.14);
    --display: "Jalnan2", sans-serif;
    --body: "Jalnan2", sans-serif;
}

* {
    box-sizing: border-box;
}

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

body.modal-open {
    overflow: hidden;
}

body {
    color: var(--ink);
    font-family: var(--body);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.42), transparent 30%),
        radial-gradient(circle at bottom right, rgba(212, 154, 47, 0.18), transparent 22%),
        linear-gradient(135deg, #f7f0e2 0%, #eed5ad 42%, #ebc190 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.14) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), transparent 90%);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.narrow-shell {
    width: min(460px, calc(100% - 32px));
    display: grid;
    align-items: center;
    min-height: 100vh;
    padding: 40px 0;
}

.hero,
.panel,
.stat-card {
    background: linear-gradient(180deg, rgba(255, 249, 239, 0.96), rgba(248, 236, 217, 0.98));
    border: 1px solid rgba(125, 34, 27, 0.12);
    box-shadow: var(--shadow);
}

.hero,
.panel {
    border-radius: 28px;
}

.hero {
    position: relative;
    overflow: hidden;
    padding: 32px;
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
}

.ticket-hero::before,
.ticket-hero::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg);
    transform: translateY(-50%);
    box-shadow: inset 0 0 0 1px rgba(31, 26, 21, 0.06);
}

.ticket-hero::before {
    left: -15px;
}

.ticket-hero::after {
    right: -15px;
}

.admin-hero {
    background:
        linear-gradient(135deg, rgba(255, 247, 234, 0.98), rgba(243, 225, 194, 0.98)),
        linear-gradient(90deg, rgba(164, 48, 38, 0.05), transparent);
}

.hero h1,
.panel h2,
.login-panel h1 {
    margin: 0;
    font-family: var(--display);
    letter-spacing: -0.02em;
}

.hero h1,
.login-panel h1 {
    font-size: clamp(2.1rem, 5vw, 3.5rem);
    line-height: 1;
}

.panel h2 {
    font-size: clamp(1.35rem, 3vw, 1.8rem);
}

.hero-copy,
.muted {
    color: var(--muted);
}

.hero-copy {
    max-width: 42rem;
    margin: 14px 0 0;
    line-height: 1.65;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.78rem;
    font-weight: 700;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 14px;
}

.auth-form {
    width: 100%;
    display: grid;
    gap: 12px;
}

.primary-button,
.secondary-button,
.secondary-link {
    border-radius: 999px;
    font-weight: 700;
    text-decoration: none;
    transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.primary-button,
.secondary-button {
    border: 0;
    cursor: pointer;
    font-family: inherit;
}

.primary-button {
    padding: 14px 24px;
    background: linear-gradient(180deg, var(--red), var(--red-deep));
    color: white;
    box-shadow: 0 14px 26px rgba(125, 34, 27, 0.26);
}

.secondary-button,
.secondary-link {
    padding: 12px 18px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--ink);
    border: 1px solid rgba(31, 26, 21, 0.08);
}

.primary-button:hover,
.secondary-button:hover,
.secondary-link:hover {
    transform: translateY(-1px);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.full-width {
    width: 100%;
}

.stat-grid {
    margin-top: 22px;
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.public-page .stat-grid + .panel {
    margin-top: 28px;
}

.stat-card {
    border-radius: 22px;
    padding: 20px 22px;
}

.stat-label {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.92rem;
}

.stat-value {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.stat-value.small {
    font-size: 1rem;
    line-height: 1.5;
}

.content-grid {
    margin-top: 22px;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
}

.panel {
    padding: 24px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.count-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.compact-grid {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
}

.count-card,
.ticket-card,
.history-item,
.result-card,
.login-panel,
.field input,
.field select {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
}

.count-card {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    padding: 16px;
}

.count-card::before,
.ticket-card::before,
.history-item::before,
.result-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: var(--accent, var(--red));
}

.count-label,
.ticket-status,
.result-time,
.result-owner {
    margin: 0;
    color: var(--muted);
}

.ticket-owner {
    margin: 0;
    color: var(--green);
    font-size: 0.88rem;
    font-weight: 700;
}

.count-value,
.result-badge,
.history-prize,
.ticket-prize,
.ticket-number {
    margin: 8px 0 0;
    font-weight: 800;
}

.count-value {
    font-size: 1.4rem;
}

.count-value span {
    font-size: 0.92rem;
    color: var(--muted);
}

.result-card {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    min-height: 260px;
    padding: 24px;
    display: grid;
    background:
        radial-gradient(circle at top right, rgba(211, 154, 47, 0.18), transparent 34%),
        rgba(255, 255, 255, 0.72);
}

.result-card.empty {
    background: rgba(255, 255, 255, 0.58);
}

.result-card.is-opening::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at center, rgba(255, 255, 255, 0.75), transparent 46%),
        radial-gradient(circle at center, rgba(211, 154, 47, 0.32), transparent 70%);
    pointer-events: none;
    animation: openingGlow 1.65s ease;
}

.result-card.reveal {
    animation: revealPulse 520ms ease;
}

.result-details {
    position: relative;
    z-index: 1;
    display: grid;
    align-content: center;
    gap: 10px;
    min-height: 100%;
    transition: opacity 220ms ease, transform 220ms ease;
}

.opening-stage {
    position: absolute;
    inset: 20px;
    z-index: 2;
    display: none;
    align-content: center;
    justify-items: center;
    gap: 18px;
    pointer-events: none;
}

.result-card.is-opening .opening-stage {
    display: grid;
}

.result-card.is-opening .result-details {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
}

.ticket-pack {
    position: relative;
    width: min(280px, 78%);
    aspect-ratio: 7 / 4.6;
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid rgba(125, 34, 27, 0.16);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.42), transparent 42%),
        linear-gradient(165deg, #fff0c9 0%, #efc46d 50%, #c67b18 100%);
    box-shadow: 0 24px 38px rgba(125, 34, 27, 0.18);
    animation: packWobble 1.65s cubic-bezier(0.25, 0.8, 0.2, 1) forwards;
}

.ticket-pack::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.2) 48%, transparent 100%),
        repeating-linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.16) 0 14px,
            rgba(255, 255, 255, 0.04) 14px 28px
        );
}

.ticket-pack::after {
    content: "";
    position: absolute;
    inset: 14px;
    border-radius: 18px;
    border: 1px dashed rgba(255, 255, 255, 0.58);
}

.ticket-pack-strip {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 16px;
    height: 20px;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--red), var(--red-deep));
    box-shadow: 0 10px 20px rgba(125, 34, 27, 0.18);
    animation: stripLift 1.65s cubic-bezier(0.26, 0.86, 0.24, 1) forwards;
}

.ticket-pack-core {
    position: absolute;
    inset: 46px 26px 26px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 249, 239, 0.94));
    box-shadow:
        inset 0 0 0 1px rgba(31, 26, 21, 0.08),
        0 14px 24px rgba(211, 154, 47, 0.18);
    opacity: 0;
    transform: translateY(26px) scale(0.85);
    animation: coreReveal 1.65s cubic-bezier(0.22, 0.9, 0.22, 1) forwards;
}

.opening-copy {
    margin: 0;
    text-align: center;
    color: var(--muted);
    line-height: 1.55;
    animation: openingCopy 1.65s ease;
}

.result-badge {
    font-size: clamp(1.7rem, 5vw, 2.6rem);
    font-family: var(--display);
}

.result-ticket {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.result-owner {
    font-weight: 700;
}

.compact {
    min-height: 0;
    padding: 18px 20px;
}

.history-list {
    display: grid;
    gap: 10px;
}

.history-item {
    position: relative;
    border-radius: 18px;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.history-title {
    margin: 0 0 6px;
    font-weight: 700;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 120px;
    color: var(--muted);
    border-radius: 18px;
    border: 1px dashed rgba(31, 26, 21, 0.16);
}

.stack-form {
    display: grid;
    gap: 14px;
}

.field {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

.field input {
    width: 100%;
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    color: var(--ink);
}

.field select {
    width: 100%;
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    color: var(--ink);
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 22px) calc(50% - 3px),
        calc(100% - 16px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.field input:focus,
.field select:focus {
    outline: 2px solid rgba(164, 48, 38, 0.18);
    border-color: rgba(164, 48, 38, 0.38);
}

.prize-input-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.login-panel {
    border-radius: 28px;
    padding: 32px;
}

.form-message {
    margin: 0;
    min-height: 1.5em;
    color: var(--muted);
}

.form-message.error {
    color: var(--red-deep);
}

.form-message.success {
    color: var(--green);
}

.secondary-grid {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}

.public-board-panel {
    margin-top: 22px;
}

.public-ticket-map {
    gap: 18px;
}

.result-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 20px;
}

.result-modal[hidden] {
    display: none;
}

.result-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(31, 26, 21, 0.46);
    backdrop-filter: blur(8px);
}

.result-modal-panel {
    position: relative;
    z-index: 1;
    width: min(520px, 100%);
}

.result-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    min-height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    font: inherit;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(31, 26, 21, 0.12);
}

.modal-card {
    min-height: 320px;
    box-shadow: 0 28px 62px rgba(31, 26, 21, 0.24);
}

.code-output,
.mini-stat,
.code-card {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
}

.code-output {
    margin-top: 16px;
    border-radius: 22px;
    padding: 18px;
}

.code-output.empty {
    opacity: 0.82;
}

.code-output-label,
.mini-stat-label,
.code-card-meta {
    margin: 0;
    color: var(--muted);
}

.code-output-value,
.mini-stat-value,
.code-card-name,
.code-card-value {
    margin: 8px 0 0;
}

.code-output-value,
.code-card-value {
    font-family: var(--display);
    font-size: 1.3rem;
    line-height: 1.45;
    word-break: break-all;
}

.code-summary {
    margin-top: 16px;
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-stat {
    border-radius: 18px;
    padding: 16px;
}

.mini-stat-value {
    font-family: var(--display);
    font-size: 1.8rem;
}

.code-list {
    display: grid;
    gap: 12px;
}

.code-card {
    border-radius: 20px;
    padding: 18px;
}

.code-card.used {
    background: rgba(240, 234, 224, 0.92);
}

.code-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.code-card-name {
    font-size: 1.02rem;
    font-weight: 800;
}

.code-card-actions {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
}

.unblock-button {
    min-height: 40px;
    padding: 0 16px;
    border-color: rgba(164, 48, 38, 0.24);
}

.unblock-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 800;
}

.pill.active {
    background: rgba(51, 93, 67, 0.12);
    color: var(--green);
}

.pill.used {
    background: rgba(164, 48, 38, 0.12);
    color: var(--red-deep);
}

.ticket-map {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
}

.ticket-card {
    position: relative;
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 10px;
    min-height: 126px;
    transition: transform 180ms ease, opacity 180ms ease;
}

.ticket-card:hover {
    transform: translateY(-2px);
}

.ticket-card.is-drawn {
    opacity: 0.64;
    background: rgba(238, 231, 220, 0.88);
}

.ticket-card.is-owned {
    opacity: 1;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(236, 246, 238, 0.94));
    box-shadow: 0 10px 24px rgba(51, 93, 67, 0.12);
}

.public-ticket-map .ticket-card:not(.is-selectable):hover {
    transform: none;
}

.public-ticket-map .ticket-card.is-selectable {
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(72, 41, 14, 0.08);
}

.public-ticket-map .ticket-card.is-selectable:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 30px rgba(72, 41, 14, 0.14);
}

.public-ticket-map .ticket-card.is-opening {
    animation: selectedTicketGlow 1.3s ease forwards;
}

.public-ticket-map .ticket-card.is-opening::after {
    content: "OPEN";
    position: absolute;
    inset: auto 12px 12px auto;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--red-deep);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.ticket-number {
    font-size: 1.05rem;
}

.ticket-prize {
    font-size: 1.18rem;
    font-family: var(--display);
}

[data-prize="A"] { --accent: #b93225; }
[data-prize="B"] { --accent: #c05e1e; }
[data-prize="C"] { --accent: #c49319; }
[data-prize="D"] { --accent: #4f7d38; }
[data-prize="E"] { --accent: #1f7f68; }
[data-prize="F"] { --accent: #22718e; }
[data-prize="G"] { --accent: #3a5fa8; }
[data-prize="H"] { --accent: #6651a6; }
[data-prize="I"] { --accent: #8f4f92; }
[data-prize="J"] { --accent: #9f4763; }
[data-prize="K"] { --accent: #7a5246; }
[data-prize="BLANK"] { --accent: #6d6459; }

@keyframes revealPulse {
    0% {
        transform: scale(0.97);
        box-shadow: 0 0 0 rgba(164, 48, 38, 0);
    }
    45% {
        transform: scale(1.02);
        box-shadow: 0 0 0 14px rgba(164, 48, 38, 0.08);
    }
    100% {
        transform: scale(1);
        box-shadow: none;
    }
}

@keyframes openingGlow {
    0% {
        opacity: 0;
        transform: scale(0.96);
    }
    52% {
        opacity: 1;
        transform: scale(1.02);
    }
    100% {
        opacity: 0;
        transform: scale(1.08);
    }
}

@keyframes packWobble {
    0% {
        transform: translateY(16px) scale(0.92) rotate(-7deg);
    }
    18% {
        transform: translateY(4px) scale(0.97) rotate(5deg);
    }
    34% {
        transform: translateY(-2px) scale(1.01) rotate(-2deg);
    }
    58% {
        transform: translateY(0) scale(1.02) rotate(1deg);
    }
    100% {
        transform: translateY(0) scale(1) rotate(0);
    }
}

@keyframes stripLift {
    0%,
    34% {
        opacity: 1;
        transform: translateY(0) scaleX(1);
    }
    60% {
        opacity: 1;
        transform: translateY(-18px) scaleX(1.05);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px) scaleX(0.92);
    }
}

@keyframes coreReveal {
    0%,
    36% {
        opacity: 0;
        transform: translateY(26px) scale(0.85);
    }
    58% {
        opacity: 1;
    }
    100% {
        opacity: 1;
        transform: translateY(-2px) scale(1.03);
    }
}

@keyframes openingCopy {
    0%,
    18% {
        opacity: 0;
        transform: translateY(8px);
    }
    36%,
    78% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0.46;
        transform: translateY(-4px);
    }
}

@keyframes selectedTicketGlow {
    0% {
        transform: translateY(0) scale(1);
        box-shadow: 0 0 0 rgba(211, 154, 47, 0);
    }
    36% {
        transform: translateY(-8px) scale(1.03);
        box-shadow: 0 0 0 10px rgba(211, 154, 47, 0.16);
    }
    100% {
        transform: translateY(0) scale(1);
        box-shadow: 0 16px 28px rgba(211, 154, 47, 0.18);
    }
}

@media (max-width: 980px) {
    .hero,
    .content-grid {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 640px) {
    .shell {
        width: min(100% - 20px, 100%);
        padding: 20px 0 32px;
    }

    .hero,
    .panel,
    .login-panel {
        padding: 20px;
        border-radius: 22px;
    }

    .stat-grid,
    .prize-input-grid {
        grid-template-columns: 1fr;
    }

    .code-summary {
        grid-template-columns: 1fr;
    }

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