@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Noto+Sans+JP:wght@400;500;700&family=Playfair+Display:wght@600;700&display=swap");

:root {
    --ink: #17221d;
    --muted-ink: #58625c;
    --paper: #f7f2e8;
    --paper-deep: #ebe3d2;
    --card: #fffdf8;
    --line: #d7ccba;
    --forest: #1f513e;
    --forest-dark: #12392b;
    --gold: #b77a1d;
    --gold-light: #f1d899;
    --red: #9f3f36;
    --shadow: 0 16px 40px rgba(42, 48, 35, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: "Noto Sans JP", sans-serif;
    background-color: var(--paper);
    background-image:
        linear-gradient(rgba(31, 81, 62, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(31, 81, 62, 0.045) 1px, transparent 1px);
    background-size: 28px 28px;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.lottery-app {
    width: min(100% - 32px, 920px);
    margin: 0 auto;
    padding: 56px 0 72px;
}

.app-header {
    position: relative;
    margin-bottom: 40px;
    padding: 28px 32px 31px;
    overflow: hidden;
    color: #fffdf6;
    background: var(--forest);
    border-left: 6px solid var(--gold);
    box-shadow: var(--shadow);
    animation: reveal 450ms ease-out both;
}

.app-header::after {
    position: absolute;
    top: -56px;
    right: -38px;
    width: 180px;
    height: 180px;
    content: "";
    border: 24px solid rgba(241, 216, 153, 0.24);
    border-radius: 50%;
}

.eyebrow,
.section-kicker {
    margin: 0 0 7px;
    color: var(--gold);
    font-family: "DM Mono", monospace;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.08em;
}

.app-header .eyebrow {
    color: var(--gold-light);
}

#appVersion {
    margin-left: 6px;
    font-size: 0.68rem;
    opacity: 0.82;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2,
h3 {
    font-weight: 700;
}

h1 {
    position: relative;
    z-index: 1;
    margin-bottom: 4px;
    font-family: "Playfair Display", serif;
    font-size: 3.2rem;
    line-height: 1;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 9px;
    font-size: 1.55rem;
    line-height: 1.35;
    letter-spacing: 0;
}

h3 {
    margin-bottom: 0;
    font-size: 1.08rem;
    letter-spacing: 0;
}

.header-copy {
    position: relative;
    z-index: 1;
    margin: 0;
    color: rgba(255, 253, 246, 0.82);
    font-size: 0.93rem;
}

.panel,
.result-panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: var(--shadow);
}

.login-panel {
    width: min(100%, 510px);
    margin: 0 auto;
    padding: 36px;
    animation: reveal 500ms 100ms ease-out both;
}

.section-description {
    margin-bottom: 26px;
    color: var(--muted-ink);
    font-size: 0.91rem;
    line-height: 1.8;
}

form {
    display: grid;
    gap: 10px;
}

label {
    font-size: 0.86rem;
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 50px;
    padding: 10px 13px;
    color: var(--ink);
    background: #fffefa;
    border: 1px solid #b8ae9e;
    border-radius: 4px;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus {
    border-color: var(--forest);
    box-shadow: 0 0 0 3px rgba(31, 81, 62, 0.15);
}

input::placeholder {
    color: #9c978d;
}

.primary-button,
.secondary-button,
.refresh-button,
.text-button {
    min-height: 44px;
    border-radius: 4px;
    font-weight: 700;
    transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.primary-button {
    margin-top: 14px;
    padding: 10px 20px;
    color: #fff;
    background: var(--forest);
    border: 1px solid var(--forest);
}

.primary-button:hover:not(:disabled) {
    background: var(--forest-dark);
    transform: translateY(-1px);
}

.secondary-button {
    padding: 10px 20px;
    color: var(--forest);
    background: transparent;
    border: 1px solid var(--forest);
}

.secondary-button:hover:not(:disabled) {
    background: #eaf0ea;
}

.form-message,
.refresh-status {
    min-height: 1.5em;
    margin: 0;
    color: var(--red);
    font-size: 0.84rem;
}

.refresh-status {
    color: var(--muted-ink);
}

.player-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    animation: reveal 400ms ease-out both;
}

.player-bar h2 {
    margin: 0;
}

.text-button {
    min-height: 36px;
    padding: 5px 0;
    color: var(--muted-ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid currentColor;
}

.text-button:hover {
    color: var(--forest);
}

.lottery-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(180px, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.prize-panel,
.chance-panel,
.draw-panel {
    padding: 26px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.refresh-button {
    min-height: 36px;
    padding: 6px 10px;
    color: var(--forest);
    background: #f7f4eb;
    border: 1px solid #aaa98e;
    font-size: 0.78rem;
    white-space: nowrap;
}

.refresh-button:hover:not(:disabled) {
    border-color: var(--forest);
    background: #eaf0ea;
}

.prize-amount,
.chance-count,
.winning-amount {
    font-family: "DM Mono", monospace;
    font-weight: 500;
    letter-spacing: 0;
}

.prize-amount {
    margin: 26px 0 10px;
    color: var(--gold);
    font-size: clamp(2rem, 5vw, 3.55rem);
    line-height: 1;
}

.notice {
    margin: 15px 0 0;
    padding-top: 14px;
    color: var(--muted-ink);
    border-top: 1px solid var(--line);
    font-size: 0.77rem;
    line-height: 1.65;
}

.chance-panel {
    background: var(--forest);
    border-color: var(--forest);
    color: #fffdf6;
}

.chance-panel .section-kicker {
    color: var(--gold-light);
}

.chance-panel p:last-child {
    margin: 25px 0 0;
}

.chance-count {
    font-size: 3.4rem;
    line-height: 0.85;
}

.chance-unit {
    margin-left: 4px;
    font-size: 0.9rem;
}

.draw-panel {
    margin-bottom: 16px;
    animation: reveal 500ms 150ms ease-out both;
}

.history-panel {
    padding: 26px;
}

.history-count {
    margin: 0;
    color: var(--muted-ink);
    font-size: 0.8rem;
}

.history-table-wrap {
    margin-top: 20px;
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th,
.history-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.history-table th {
    color: var(--muted-ink);
    font-size: 0.75rem;
    font-weight: 700;
}

.history-table td:nth-child(2) {
    font-family: "DM Mono", monospace;
}

.history-empty {
    padding: 24px 10px !important;
    color: var(--muted-ink);
    text-align: center !important;
}

.history-winner {
    color: var(--gold);
    font-weight: 700;
}

.history-lose {
    color: var(--muted-ink);
}

.draw-panel form {
    max-width: 430px;
}

#drawNumber {
    color: var(--forest-dark);
    font-family: "DM Mono", monospace;
    font-size: 1.65rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-align: center;
}

.draw-number-control {
    display: flex;
    align-items: stretch;
    gap: 8px;
    max-width: 290px;
}

.draw-number-control #drawNumber {
    min-width: 0;
}

.clear-button {
    min-width: 72px;
    padding: 8px 10px;
    color: var(--muted-ink);
    background: #f7f4eb;
    border: 1px solid #aaa98e;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
}

.clear-button:hover:not(:disabled) {
    color: var(--forest);
    border-color: var(--forest);
    background: #eaf0ea;
}

.input-hint {
    margin: 0 0 5px;
    color: var(--muted-ink);
    font-size: 0.78rem;
}

.draw-panel .primary-button {
    max-width: 250px;
}

.result-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 190px;
    margin-bottom: 16px;
    padding: 18px 20px;
    border-left: 6px solid var(--red);
    animation: reveal 300ms ease-out both;
}

.result-panel[data-result="pending"] {
    border-left-color: #c7a67d;
    box-shadow: none;
}

.result-panel[data-result="winner"] {
    border-left-color: var(--gold);
    background: #fff9e7;
}

.result-panel h3 {
    margin-bottom: 3px;
    font-size: 1.2rem;
}

.result-panel > p:not(.section-kicker):not(.winning-amount) {
    margin-bottom: 0;
}

.winning-amount {
    margin: 4px 0 0;
    color: var(--gold);
    font-size: 1.35rem;
}

.confirm-dialog {
    width: min(100% - 32px, 440px);
    padding: 0;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 24px 70px rgba(22, 33, 27, 0.3);
}

.confirm-dialog::backdrop {
    background: rgba(18, 39, 29, 0.58);
}

.result-dialog {
    width: min(100% - 32px, 440px);
    padding: 0;
    color: var(--ink);
    background: #fff9e7;
    border: 1px solid var(--gold);
    border-radius: 6px;
    box-shadow: 0 24px 70px rgba(22, 33, 27, 0.3);
}

.result-dialog::backdrop {
    background: rgba(18, 39, 29, 0.66);
}

.result-dialog-content {
    padding: 34px 30px 30px;
    text-align: center;
}

.result-dialog-content h2 {
    margin-bottom: 12px;
    font-size: 2rem;
}

.result-dialog-content > p:not(.section-kicker):not(.winning-amount) {
    margin-bottom: 0;
    line-height: 1.7;
}

.result-dialog-content .winning-amount {
    margin: 22px 0 4px;
    font-size: 2.55rem;
}

.result-instructions {
    margin: 18px 0 0;
    padding: 13px;
    color: var(--forest-dark);
    background: rgba(241, 216, 153, 0.34);
    border-left: 3px solid var(--gold);
    font-size: 0.85rem;
    line-height: 1.7;
    text-align: left;
}

.result-dialog-content .primary-button {
    width: 100%;
    margin-top: 26px;
}

.confirm-dialog form {
    padding: 30px;
}

.confirm-dialog h2 {
    margin-bottom: 18px;
}

.confirm-dialog p {
    margin-bottom: 0;
    line-height: 1.7;
}

.confirm-note {
    color: var(--red);
    font-size: 0.88rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.dialog-actions .primary-button {
    margin-top: 0;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 640px) {
    .lottery-app {
        width: min(100% - 24px, 920px);
        padding: 28px 0 48px;
    }

    .app-header {
        margin-bottom: 28px;
        padding: 25px 22px;
    }

    h1 {
        font-size: 2.55rem;
    }

    .login-panel,
    .prize-panel,
    .chance-panel,
    .draw-panel,
    .history-panel {
        padding: 23px 20px;
    }

    .lottery-layout {
        grid-template-columns: 1fr;
    }

    .player-bar {
        align-items: flex-start;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .prize-amount {
        margin-top: 20px;
    }

    .refresh-button,
    .draw-panel .primary-button {
        width: 100%;
        max-width: none;
    }

    #drawNumber {
        max-width: none;
    }

    .draw-number-control {
        max-width: none;
    }

    .dialog-actions {
        flex-direction: column-reverse;
    }

    .dialog-actions button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.result-panel .result-instructions {
    margin-top: 5px;
    padding: 6px 8px;
    font-size: 0.76rem;
    line-height: 1.4;
}