:root {
    --teal: #004643;
    --white: #fffffe;
    --mint: #abd1c6;
    --gold: #f9bc60;
    --ink: #001e1d;
    --gray: #e8e4e6;
    --coral: #e16162;
    --shadow: 0 10px 28px rgba(0, 30, 29, 0.12);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft JhengHei', '微軟正黑體', sans-serif;
    color: var(--ink);
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background: var(--mint);
}

.page-shell {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.page-gallery-shell {
    max-width: 1100px;
}

/* 標題區 */
.page-header {
    text-align: center;
    margin-bottom: 28px;
    animation: pop-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.header-mark {
    display: inline-block;
    width: 56px;
    height: 56px;
    margin-bottom: 14px;
    background: var(--gold);
    border: 4px solid var(--teal);
    border-radius: 50%;
    animation: wiggle 3s ease-in-out infinite;
}

@keyframes pop-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-3deg); }
    50%      { transform: rotate(3deg); }
}

.page-header h1 {
    margin: 0;
    font-size: clamp(1.75rem, 5vw, 2.25rem);
    font-weight: 800;
    color: var(--ink);
}

.page-header p {
    margin: 8px 0 0;
    color: var(--teal);
    font-size: 0.95rem;
    font-weight: 700;
}

/* 訊息 */
.flash {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    margin: 0 auto 20px;
    max-width: 520px;
    text-align: center;
    font-weight: 700;
    animation: slide-down 0.4s ease both;
    border: 3px solid var(--ink);
}

@keyframes slide-down {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.flash.error {
    background: var(--white);
    color: var(--coral);
    border-color: var(--coral);
}

.flash.success {
    background: var(--white);
    color: var(--teal);
    border-color: var(--teal);
}

/* 表單卡片 */
.upload-box,
.filter-box,
.gallery-container {
    animation: pop-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.12s both;
}

.upload-box {
    background: var(--white);
    border: 4px dashed var(--teal);
    padding: 28px 28px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: border-color 0.25s, transform 0.25s;
}

.upload-box:hover {
    border-color: var(--gold);
    transform: translateY(-2px);
}

.field {
    margin-bottom: 20px;
}

.field > label:first-child,
.field-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--ink);
}

/* 下拉選單 */
select {
    width: 100%;
    padding: 12px 14px;
    border: 3px solid var(--gray);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    background: var(--white);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23004643'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

select:hover,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(171, 209, 198, 0.8);
    outline: none;
}

/* Pill 選項 */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.pill-group label {
    position: relative;
    cursor: pointer;
}

.pill-group input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.pill-group span {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.92rem;
    background: var(--gray);
    color: var(--teal);
    border: 3px solid var(--gray);
    transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pill-group input:checked + span {
    background: var(--teal);
    color: var(--white);
    border-color: var(--ink);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 70, 67, 0.25);
}

.pill-group label:hover span {
    border-color: var(--teal);
    transform: translateY(-2px);
}

.pill-group input:focus-visible + span {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

/* 檔案上傳區 */
.file-drop {
    position: relative;
    border: 3px dashed var(--mint);
    border-radius: var(--radius-md);
    padding: 24px 16px;
    text-align: center;
    background: var(--gray);
    transition: border-color 0.25s, background 0.25s, transform 0.25s;
}

.file-drop:hover,
.file-drop.is-dragover {
    border-color: var(--gold);
    background: var(--white);
    transform: scale(1.01);
}

.file-drop-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--teal);
    margin-bottom: 10px;
    animation: bounce-soft 2s ease-in-out infinite;
}

@keyframes bounce-soft {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

.file-drop input[type="file"] {
    width: 100%;
    font-family: inherit;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
}

.file-preview {
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--teal);
    min-height: 1.2em;
}

.notice-box {
    background: var(--gold);
    border: 3px solid var(--ink);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-top: 12px;
    font-size: 0.88rem;
    color: var(--ink);
    line-height: 1.6;
    font-weight: 700;
}

.field-panel.hidden {
    display: none;
}

.field-panel.is-entering {
    animation: panel-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes panel-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.hidden {
    display: none;
}

/* 按鈕 */
.btn-primary,
.filter-box button,
.page-upload input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 14px 32px;
    width: 100%;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ink);
    background: var(--gold);
    border: 3px solid var(--ink);
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--teal);
    transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
}

.btn-primary:hover,
.filter-box button:hover,
.page-upload input[type="submit"]:hover {
    background: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--teal);
}

.btn-primary:active,
.filter-box button:active,
.page-upload input[type="submit"]:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--teal);
}

.btn-primary.is-loading {
    pointer-events: none;
    opacity: 0.8;
    background: var(--mint);
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 28px;
    padding: 12px 24px;
    color: var(--white);
    font-weight: 800;
    text-decoration: none;
    background: var(--teal);
    border-radius: 999px;
    border: 3px solid var(--ink);
    transition: all 0.22s;
    animation: pop-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s both;
}

.nav-link:hover {
    background: var(--white);
    color: var(--teal);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--ink);
}

.nav-row {
    text-align: center;
}

.nav-row--compact {
    margin-bottom: 20px;
}

/* 素材庫 */
.filter-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 3px solid var(--teal);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    justify-content: center;
}

.filter-box label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 800;
    font-size: 0.9rem;
    color: var(--ink);
    min-width: 160px;
}

.filter-box select {
    width: 100%;
}

.filter-box button {
    width: auto;
    min-width: 120px;
    margin-top: 0;
}

.gallery-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
    margin-top: 32px;
}

.file-card {
    background: var(--white);
    border: 4px solid var(--mint);
    padding: 16px;
    border-radius: var(--radius-md);
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.25s;
    animation: card-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.file-card:nth-child(1) { animation-delay: 0.05s; }
.file-card:nth-child(2) { animation-delay: 0.1s; }
.file-card:nth-child(3) { animation-delay: 0.15s; }
.file-card:nth-child(4) { animation-delay: 0.2s; }
.file-card:nth-child(5) { animation-delay: 0.25s; }
.file-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes card-in {
    from { opacity: 0; transform: translateY(16px) scale(0.94); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.file-card:hover {
    transform: translateY(-6px);
    border-color: var(--gold);
}

.file-name {
    font-size: 0.78rem;
    color: var(--teal);
    margin-bottom: 10px;
    word-break: break-all;
    font-weight: 700;
}

.file-card img {
    width: 100%;
    max-width: 180px;
    height: 160px;
    object-fit: contain;
    display: block;
    border-radius: var(--radius-sm);
    margin: 0 auto 14px;
    background: var(--gray);
    padding: 8px;
    border: 2px solid var(--mint);
    transition: transform 0.25s;
}

.file-card:hover img {
    transform: scale(1.04);
}

.btn-delete {
    display: inline-block;
    background: var(--coral);
    color: var(--white);
    padding: 8px 20px;
    text-decoration: none;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 800;
    border: 3px solid var(--ink);
    transition: transform 0.2s, background 0.2s;
}

.btn-delete:hover {
    background: var(--white);
    color: var(--coral);
    transform: scale(1.05);
}

.empty-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 4px dashed var(--teal);
    color: var(--teal);
    font-size: 1.05rem;
    font-weight: 700;
}

.gallery-count {
    text-align: center;
    margin-top: 16px;
    font-weight: 800;
    color: var(--ink);
    font-size: 0.95rem;
    background: var(--gold);
    display: inline-block;
    width: 100%;
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 3px solid var(--ink);
}

@media (max-width: 520px) {
    .page-shell {
        padding: 20px 14px 36px;
    }

    .upload-box {
        padding: 20px 16px;
    }

    .pill-group span {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}
