* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    color: #2a1820;
    font-family: Arial, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
    background:
        radial-gradient(circle at 50% 16%, rgba(255, 239, 157, .55), transparent 34rem),
        linear-gradient(135deg, #fff6d8 0%, #ffd3df 42%, #bef0ea 100%);
}

button,
input {
    font: inherit;
}

[hidden] {
    display: none !important;
}

.site-auth-bar {
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 20;
    display: flex;
    justify-content: flex-end;
}

.guest-actions,
.user-info {
    display: flex;
    gap: 8px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, .58);
    border-radius: 999px;
    padding: 6px;
    background: rgba(255, 250, 240, .72);
    box-shadow: 0 14px 32px rgba(127, 54, 18, .16);
    backdrop-filter: blur(10px);
}

.user-info span {
    max-width: 128px;
    overflow: hidden;
    padding-left: 8px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-ghost-button,
.auth-primary-button {
    min-height: 36px;
    border: 0;
    border-radius: 999px;
    padding: 0 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 900;
}

.auth-ghost-button {
    color: #7d2d35;
    background: rgba(255, 255, 255, .74);
}

.auth-primary-button {
    color: #fff;
    background: linear-gradient(135deg, #f04455, #ff8b1f);
    box-shadow: 0 10px 18px rgba(196, 59, 25, .22);
}

.lottery-app {
    width: 100%;
    min-height: 100vh;
    padding: clamp(14px, 3vw, 36px);
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 18px;
}

.wheel-stage {
    min-width: 0;
    display: grid;
    place-items: center;
}

.wheel-wrap {
    position: relative;
    width: min(86vmin, 760px);
    aspect-ratio: 1;
}

.wheel-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    transform: rotate(var(--wheel-angle, 0deg));
    transform-origin: 50% 50%;
    transition: transform 5.8s cubic-bezier(.08, .72, .12, 1);
    user-select: none;
    -webkit-user-drag: none;
    filter: drop-shadow(0 22px 38px rgba(127, 54, 18, .26));
    backface-visibility: hidden;
    transform-style: preserve-3d;
    will-change: transform;
}

.pointer-img {
    width: 100%;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.pointer-button {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 5;
    width: 21%;
    aspect-ratio: 210 / 310;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    transform: translate3d(-50%, -66.2%, 0);
}

.pointer-button:disabled {
    cursor: wait;
}

.pointer-button:focus-visible {
    outline: none;
}

.pointer-button:focus-visible .pointer-img {
    filter: drop-shadow(0 0 0.35rem rgba(217, 41, 95, .8));
}

.wheel-wrap.is-spinning .wheel-img {
    transition-duration: 5.6s;
}

.winner-board {
    width: min(920px, calc(100vw - 28px));
    border: 1px solid rgba(255, 255, 255, .58);
    border-radius: 8px;
    padding: 16px;
    background: rgba(255, 250, 240, .72);
    box-shadow: 0 18px 40px rgba(127, 54, 18, .14);
    backdrop-filter: blur(10px);
}

.winner-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.winner-tabs button {
    min-height: 42px;
    border: 1px solid rgba(77, 43, 54, .14);
    border-radius: 8px;
    padding: 0 16px;
    color: #6d5960;
    background: rgba(255, 255, 255, .66);
    cursor: pointer;
    font-size: 20px;
    font-weight: 900;
}

.winner-tabs button.is-active {
    color: #2a1820;
    border-color: rgba(217, 41, 95, .38);
    background: #fff;
    box-shadow: 0 8px 22px rgba(217, 41, 95, .12);
}

.winner-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.winner-item {
    min-width: 0;
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border: 1px solid rgba(77, 43, 54, .1);
    border-radius: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, .74);
}

.winner-item img {
    width: 58px;
    height: 58px;
    object-fit: contain;
}

.winner-item strong {
    display: block;
    margin-bottom: 3px;
    font-size: 15px;
}

.winner-item p {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: #6d5960;
    font-size: 13px;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.winner-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 16px;
    color: #6d5960;
    text-align: center;
}

.rules-panel {
    display: grid;
    gap: 16px;
    border: 1px solid rgba(77, 43, 54, .1);
    border-radius: 8px;
    padding: 18px;
    background: rgba(255, 255, 255, .74);
}

.rules-panel section {
    display: grid;
    gap: 6px;
}

.rules-panel h3 {
    margin: 0 0 4px;
    font-size: 18px;
}

.rules-panel p {
    margin: 0;
    color: #5f4c53;
    font-size: 14px;
    line-height: 1.7;
}

.rules-note {
    font-weight: 800;
}

.play-panel {
    display: none;
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-row input {
    min-width: 0;
    height: 52px;
    flex: 1;
    border: 2px solid rgba(77, 43, 54, .22);
    border-radius: 8px;
    padding: 0 14px;
    background: rgba(255, 255, 255, .82);
    outline: none;
    text-transform: uppercase;
}

.input-row input:focus {
    border-color: #d9295f;
    box-shadow: 0 0 0 4px rgba(217, 41, 95, .14);
}

.input-row button,
.modal-ok,
.admin-form button {
    min-height: 52px;
    border: 0;
    border-radius: 8px;
    padding: 0 22px;
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    background: linear-gradient(135deg, #f04455, #ff8b1f);
    box-shadow: 0 12px 24px rgba(196, 59, 25, .25);
}

.input-row button:disabled {
    cursor: wait;
    opacity: .62;
}

.status-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    margin: 0;
}

.modal[hidden]:not(.is-open) {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 18px;
    overflow-x: hidden;
    overflow-y: auto;
}

.modal.is-open {
    display: grid !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(40, 18, 22, .58);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    width: min(440px, calc(100vw - 32px));
    max-width: 100%;
    border-radius: 8px;
    padding: 24px;
    background: #fffaf0;
    box-shadow: 0 24px 70px rgba(40, 18, 22, .35);
    text-align: center;
}

.modal-dialog h2 {
    margin: 0 0 12px;
    font-size: 24px;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
}

.result-pic {
    max-width: min(220px, 70%);
    max-height: 220px;
    object-fit: contain;
    margin: 4px auto 14px;
    display: block;
}

.result-desc {
    margin: 0 0 18px;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.code-dialog {
    display: grid;
    gap: 14px;
}

.auth-form-dialog {
    display: grid;
    gap: 14px;
    text-align: left;
}

.auth-form-dialog h2 {
    text-align: center;
}

.auth-form-dialog label {
    display: grid;
    gap: 7px;
    font-weight: 900;
}

.auth-form-dialog label span {
    color: #4d2b36;
    font-size: 14px;
}

.code-error {
    margin: 0;
    border-radius: 8px;
    padding: 10px 12px;
    color: #b42318;
    font-weight: 800;
    line-height: 1.6;
    background: #fff1f0;
}

.auth-message {
    margin: 0 0 18px;
    font-size: 20px;
    font-weight: 900;
    line-height: 1.6;
}

.code-dialog input,
.auth-form-dialog input {
    width: 100%;
    height: 52px;
    border: 2px solid rgba(77, 43, 54, .22);
    border-radius: 8px;
    padding: 0 14px;
    outline: none;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.auth-form-dialog input {
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
}

.code-dialog input:focus,
.auth-form-dialog input:focus {
    border-color: #d9295f;
    box-shadow: 0 0 0 4px rgba(217, 41, 95, .14);
}

.auth-switch {
    margin: 0;
    color: #6d5960;
    font-size: 14px;
    text-align: center;
}

.auth-switch button {
    border: 0;
    padding: 0;
    color: #d9295f;
    background: transparent;
    cursor: pointer;
    font-weight: 900;
}

.prizes-dialog {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 36px);
    overflow-y: auto;
    text-align: left;
}

.prizes-dialog h2 {
    text-align: center;
}

.prizes-section {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.prizes-section h3 {
    margin: 0;
    color: #4d2b36;
    font-size: 17px;
}

.prizes-notice {
    margin: 0;
    border-radius: 8px;
    padding: 10px 12px;
    color: #176434;
    font-weight: 900;
    text-align: center;
    background: #e9f9ef;
}

.prizes-notice.is-error {
    color: #b42318;
    background: #fff1f0;
}

.owned-prizes-list,
.fragment-list {
    display: grid;
    gap: 10px;
}

.owned-prize-item,
.fragment-item {
    min-width: 0;
    display: grid;
    gap: 10px;
    align-items: center;
    border: 1px solid rgba(77, 43, 54, .1);
    border-radius: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, .78);
}

.owned-prize-item {
    grid-template-columns: 64px minmax(0, 1fr);
}

.fragment-item {
    grid-template-columns: 58px minmax(0, 1fr) auto;
}

.owned-prize-item img,
.fragment-item img,
.owned-prize-placeholder {
    width: 58px;
    height: 58px;
    object-fit: contain;
}

.owned-prize-placeholder {
    display: block;
    border-radius: 8px;
    background: rgba(77, 43, 54, .08);
}

.owned-prize-item strong,
.fragment-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: 15px;
}

.owned-prize-item p {
    margin: 0;
    color: #6d5960;
    font-size: 13px;
    line-height: 1.5;
}

.fragment-main {
    min-width: 0;
}

.fragment-main span {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 10px;
    color: #d9295f;
    font-weight: 900;
    background: #fff1f0;
}

.fragment-item button {
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 0 14px;
    color: #fff;
    cursor: pointer;
    font-weight: 900;
    background: linear-gradient(135deg, #f04455, #ff8b1f);
}

.fragment-item button:disabled {
    color: #9aa0aa;
    cursor: not-allowed;
    background: #eef0f4;
    box-shadow: none;
}

.prizes-empty {
    margin: 0;
    border-radius: 8px;
    padding: 14px;
    color: #6d5960;
    text-align: center;
    background: rgba(255, 255, 255, .64);
}

.admin-page {
    background: #f6f7fb;
}

.admin-layout {
    width: min(1380px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 18px;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
}

.admin-sidebar,
.admin-panel {
    border: 1px solid #dfe3eb;
    border-radius: 8px;
    background: #fff;
}

.admin-sidebar {
    align-self: start;
    position: sticky;
    top: 18px;
    padding: 18px;
}

.admin-sidebar h1 {
    margin: 0 0 18px;
    font-size: 24px;
}

.admin-sidebar nav {
    display: grid;
    gap: 8px;
}

.admin-sidebar a,
.text-link,
.primary-link,
.actions a {
    color: #26324a;
    text-decoration: none;
}

.admin-sidebar a {
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 700;
}

.admin-sidebar a.active,
.admin-sidebar a:hover {
    background: #edf3ff;
    color: #1655c7;
}

.admin-main {
    min-width: 0;
    display: grid;
    gap: 16px;
}

.admin-panel {
    min-width: 0;
    padding: 20px;
}

.admin-panel h1,
.admin-panel h2 {
    margin: 0 0 16px;
}

.panel-title {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-title h2 {
    margin: 0;
}

.primary-link {
    border-radius: 8px;
    padding: 10px 14px;
    color: #fff;
    font-weight: 800;
    background: linear-gradient(135deg, #f04455, #ff8b1f);
}

.text-link,
.actions a {
    font-weight: 700;
}

.notice {
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff5cf;
}

.notice.success {
    background: #e9f9ef;
    color: #176434;
}

.notice.error,
#probabilityTotal.is-error {
    background: #ffe8eb;
    color: #ba1d36;
}

.created-code {
    margin-bottom: 16px;
    padding: 14px;
    border-radius: 8px;
    background: #151923;
    color: #fff;
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 3px;
    text-align: center;
}

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

.admin-form > label,
.form-grid label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 14px;
}

.admin-form input[type="number"],
.admin-form input[type="text"],
.admin-form textarea {
    width: 100%;
    height: 42px;
    border: 1px solid #cfd5df;
    border-radius: 8px;
    padding: 0 10px;
    background: #fff;
}

.admin-form textarea {
    height: auto;
    padding: 10px;
    resize: vertical;
}

.admin-form input:disabled,
.admin-form textarea:disabled,
.admin-form button:disabled {
    opacity: .62;
    cursor: not-allowed;
}

.probability-head {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.probability-head h2 {
    margin: 0;
    font-size: 20px;
}

.probability-head strong {
    border-radius: 8px;
    padding: 8px 10px;
    background: #f3f6fb;
}

.prize-table {
    display: grid;
    gap: 8px;
}

.prize-row {
    display: grid;
    grid-template-columns: auto 48px minmax(0, 1fr) 78px;
    gap: 10px;
    align-items: center;
    border: 1px solid #edf0f5;
    border-radius: 8px;
    padding: 8px;
}

.probability-row {
    grid-template-columns: 56px minmax(0, 1fr) 110px auto;
}

.prize-row img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.prize-row span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.admin-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    min-width: 920px;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    border-bottom: 1px solid #edf0f5;
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    color: #5b6475;
    font-size: 13px;
    white-space: nowrap;
    background: #f8fafd;
}

.code-table td:nth-child(7) {
    min-width: 260px;
}

.admin-prize-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.admin-prize-badges span {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    border: 1px solid #e5eaf2;
    border-radius: 999px;
    padding: 4px 8px;
    background: #fff;
    font-size: 12px;
    white-space: nowrap;
}

.admin-prize-badges img,
.log-prize img,
.win-tip img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.actions {
    min-width: 150px;
}

.actions,
.actions form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.actions button {
    border: 0;
    border-radius: 8px;
    padding: 6px 10px;
    color: #fff;
    cursor: pointer;
    background: #1655c7;
}

.empty-cell {
    padding: 28px !important;
    color: #788295;
    text-align: center !important;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 16px;
}

.detail-grid div {
    border: 1px solid #edf0f5;
    border-radius: 8px;
    padding: 12px;
    background: #fbfcff;
}

.detail-grid dt {
    color: #667085;
    font-size: 13px;
}

.detail-grid dd {
    margin: 6px 0 0;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.log-prize {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.win-tip {
    display: flex;
    gap: 12px;
    border: 1px solid #ffe1a8;
    border-radius: 8px;
    margin-top: 12px;
    padding: 12px;
    background: #fffaf0;
}

.win-tip img {
    width: 58px;
    height: 58px;
}

.win-tip p {
    margin: 6px 0 0;
    line-height: 1.7;
}

@media (max-width: 820px) {
    .lottery-app,
    .admin-layout,
    .form-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .lottery-app {
        place-items: center;
    }

    .wheel-wrap {
        width: min(92vmin, 560px);
    }

    .winner-list {
        grid-template-columns: 1fr;
    }

    .winner-tabs button {
        flex: 1;
        min-width: 0;
        padding: 0 10px;
        font-size: 16px;
    }

    .admin-sidebar {
        position: static;
    }

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

@media (max-width: 460px) {
    .site-auth-bar {
        position: relative;
        top: auto;
        right: auto;
        left: auto;
        width: 100%;
        padding: 10px 12px 0;
        justify-content: center;
    }

    .guest-actions,
    .user-info {
        width: min(100%, 420px);
        justify-content: center;
    }

    .user-info span {
        max-width: 120px;
    }

    .auth-ghost-button,
    .auth-primary-button {
        padding: 0 12px;
        font-size: 13px;
    }

    .lottery-app {
        min-height: auto;
        padding-top: 10px;
    }

    .input-row {
        display: grid;
    }

    .input-row input,
    .input-row button {
        width: 100%;
    }

    .modal-dialog {
        width: calc(100vw - 24px);
        padding: 22px 14px;
    }

    .code-dialog input {
        min-width: 0;
    }

    .fragment-item,
    .owned-prize-item {
        grid-template-columns: 48px minmax(0, 1fr);
    }

    .fragment-item button {
        grid-column: 1 / -1;
        width: 100%;
    }

    .owned-prize-item img,
    .fragment-item img,
    .owned-prize-placeholder {
        width: 48px;
        height: 48px;
    }
}
