/* Shared colours, typefaces, and layout measurements. */
:root {
    --paper: #ffffff;
    --off-white: #f7f6f2;
    --ink: #181818;
    --muted: #686761;
    --line: #deddd7;
    --sidebar-width: 232px;
    --font-body: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Yu Gothic", Arial, sans-serif;
    --font-heading: "Iowan Old Style", "Palatino Linotype", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
}

* {
    box-sizing: border-box;
}

/* Keep JavaScript-controlled views and controls hidden, even inside grids. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    max-width: 100%;
    min-height: 44px;
    padding: 11px 20px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.4;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

button:not(:disabled):hover {
    border-color: var(--ink);
    background: var(--off-white);
}

button:disabled {
    opacity: 0.45;
    cursor: default;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 4px;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h2 {
    margin-bottom: 32px;
    font-family: var(--font-heading);
    font-size: clamp(32px, 4vw, 48px);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.025em;
    overflow-wrap: anywhere;
}

h3 {
    margin: 48px 0 20px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.02em;
}

p {
    margin-bottom: 20px;
}

/* Persistent, Japanese-first sidebar. */
.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    padding: 48px 28px;
    background: var(--off-white);
    border-right: 1px solid var(--line);
}

.sidebar h1 {
    margin: 0 0 88px 14px;
    font-size: 25px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.06em;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.nav-button {
    width: 100%;
    padding: 16px 14px;
    border: 0;
    border-left: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    text-align: left;
}

.nav-button [lang="ja"] {
    display: block;
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 400;
    line-height: 1.4;
    letter-spacing: 0.06em;
}

.nav-translation {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.06em;
}

.nav-button.active,
.nav-button:not(:disabled):hover {
    background: var(--paper);
    border-left-color: var(--ink);
}

.nav-button.active .nav-translation {
    color: var(--ink);
}

/* Spacious page composition; all views share the same content edge. */
.main-content {
    position: relative;
    isolation: isolate;
    min-width: 0;
    padding: clamp(40px, 6vw, 88px) clamp(24px, 6vw, 88px) 96px;
}

#homeView,
.deck-section {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1040px;
    margin-inline: auto;
}

#homeView header {
    margin: 24px 0 clamp(64px, 9vw, 120px);
}

.japanese-heading {
    margin-bottom: 22px;
    font-family: var(--font-heading);
    font-size: clamp(30px, 4.3vw, 58px);
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0.03em;
    overflow-wrap: anywhere;
}

#homeView header h2 {
    margin: 0;
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: 0.015em;
}

/* Two decorative swimmers share a viewport layer behind all main views. */
#homeView {
    min-height: 760px;
}

.scene-artwork {
    position: fixed;
    inset: 0 0 0 var(--sidebar-width);
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
}

.jellyfish-swimmer {
    --art-opacity: 1;
    position: absolute;
    top: 64px;
    right: 8%;
    width: min(80%, 680px);
    height: 800px;
    opacity: var(--art-opacity);
    transform-origin: 50% 30%;
}

/* Inner motion keeps swaying independent of the outer navigation transform. */
.jellyfish-drift {
    width: 100%;
    height: 100%;
    animation: jellyfish-drift 19s ease-in-out -7s infinite;
}

.jellyfish-image {
    --jellyfish-facing: 1;
    --jellyfish-tilt: 0deg;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: top right;
    transform-origin: 55% 25%;
    animation: jellyfish-sway 27s ease-in-out -11s infinite;
}

#jellyfishTwo .jellyfish-drift {
    animation-duration: 23s;
    animation-delay: -13s;
}

#jellyfishTwo .jellyfish-image {
    --jellyfish-facing: -1;
    --jellyfish-tilt: 3deg;
    animation-duration: 31s;
    animation-delay: -19s;
}

@keyframes jellyfish-drift {
    0%, 100% { transform: translate(-3px, 4px); }
    50% { transform: translate(4px, -5px); }
}

@keyframes jellyfish-sway {
    0%, 100% {
        transform: scaleX(var(--jellyfish-facing)) rotate(calc(var(--jellyfish-tilt) - 1.2deg));
    }
    50% {
        transform: scaleX(var(--jellyfish-facing)) rotate(calc(var(--jellyfish-tilt) + 1.2deg));
    }
}

.motion-paused .jellyfish-drift,
.motion-paused .jellyfish-image,
.jellyfish-swimmer[hidden] .jellyfish-drift,
.jellyfish-swimmer[hidden] .jellyfish-image {
    animation-play-state: paused;
}

.jellyfish-swimmer[data-view="libraryView"] {
    --art-opacity: 0.18;
    top: 100px;
    right: -6%;
}

.jellyfish-swimmer[data-view="deckView"] {
    --art-opacity: 0.14;
    top: 120px;
    right: -12%;
}

.jellyfish-swimmer[data-view="studyView"] {
    --art-opacity: 0.2;
    top: 40px;
    right: -4%;
}

#homeContent {
    position: relative;
    z-index: 1;
    display: flow-root;
}

#homeView header {
    max-width: 74%;
}

.recent-deck-panel {
    max-width: 520px;
    margin-top: 48px;
    padding: 28px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.9);
}

/* The solid translucent background also works without backdrop-filter. */
@supports (backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px)) {
    .recent-deck-panel {
        background: rgba(255, 255, 255, 0.78);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
    }
}

.recent-deck-panel h3 {
    margin: 0 0 20px;
}

.recent-deck-panel .deck {
    background: transparent;
}

.recent-deck-panel .deck:not(:disabled):hover {
    background: rgba(247, 246, 242, 0.8);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 48px;
}

.section-heading h2 {
    margin: 0;
}

.library-actions,
.card-actions,
.study-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

#createDeckButton,
#libraryCreateDeckButton,
#saveCardButton,
#studyButton {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--paper);
}

#createDeckButton:not(:disabled):hover,
#libraryCreateDeckButton:not(:disabled):hover,
#saveCardButton:not(:disabled):hover,
#studyButton:not(:disabled):hover {
    background: #383838;
    border-color: #383838;
}

#backButton,
#backToFoldersButton,
#exitStudyButton {
    margin: 0 0 32px;
    padding-inline: 0;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
}

#backButton:hover,
#backToFoldersButton:hover,
#exitStudyButton:hover {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: 5px;
}

/* Decks and folders borrow the sidebar's quiet backgrounds and left marker. */
.deck-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
    gap: 20px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.deck,
.folder {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    min-height: 148px;
    padding: 24px;
    border: 0;
    border-left: 2px solid transparent;
    border-radius: 12px;
    background: var(--off-white);
    text-align: left;
    overflow-wrap: anywhere;
}

.deck:not(:disabled):hover,
.folder:not(:disabled):hover,
.deck:focus-visible,
.folder:focus-visible {
    border-left-color: var(--ink);
}

.folder {
    min-height: 132px;
    background: var(--off-white);
}

.tile-title {
    max-width: 100%;
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 400;
    line-height: 1.3;
    letter-spacing: -0.015em;
}

.tile-count {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

#recentDeckContainer {
    max-width: 440px;
}

#folderSection {
    margin-bottom: 48px;
}

/* Existing deck-management forms and cards. */
.folder-assignment {
    margin-bottom: 28px;
}

.folder-assignment label,
form label {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

#deckFolderSelect {
    max-width: 100%;
    min-height: 44px;
    margin-left: 12px;
    padding: 8px 36px 8px 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--paper);
    color: var(--ink);
    font-size: 13px;
}

#importHelp {
    max-width: 640px;
    color: var(--muted);
    font-size: 13px;
}

#addCardForm,
#importForm {
    display: grid;
    gap: 12px;
    max-width: 640px;
}

form button {
    justify-self: start;
}

#addCardForm textarea {
    width: 100%;
    min-height: 116px;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--off-white);
    color: var(--ink);
    line-height: 1.6;
    resize: vertical;
}

#importFile {
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--off-white);
    color: var(--muted);
    font-size: 13px;
}

#importFile::file-selector-button {
    margin-right: 16px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    cursor: pointer;
}

.card-container {
    display: grid;
    gap: 0;
    border-top: 1px solid var(--line);
    margin-bottom: 48px;
}

.card {
    padding: 28px 0;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.card h4 {
    margin: 0 0 16px;
    font-family: var(--font-heading);
    font-size: 23px;
    font-weight: 400;
    line-height: 1.45;
    white-space: pre-wrap;
}

.card p {
    max-width: 760px;
    margin: 0;
    white-space: pre-wrap;
}

.card .card-priority {
    margin-top: 16px;
    color: var(--muted);
    font-size: 11px;
}

.card-actions {
    margin-top: 20px;
}

.card-actions button {
    padding: 8px 16px;
    font-size: 12px;
}

#cardMessage,
#importMessage,
#folderMessage,
#studyMessage {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

#cardMessage:empty,
#importMessage:empty,
#folderMessage:empty,
#studyMessage:empty {
    display: none;
}

/* Study presentation only: reveal and rating behaviour stays in JavaScript. */
#studyView {
    max-width: 880px;
}

#studyHint {
    margin-bottom: 24px;
    color: var(--muted);
    font-size: 13px;
}

#studyCard {
    display: block;
    width: 100%;
    min-height: 320px;
    padding: clamp(24px, 5vw, 64px);
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--off-white);
    font-family: var(--font-heading);
    font-size: clamp(24px, 3vw, 36px);
    font-weight: 400;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

#studyCard:not(:disabled):hover {
    border-color: var(--ink);
    background: var(--off-white);
}

#studyCard:disabled {
    opacity: 1;
}

#studyQuestion,
#studyAnswer {
    display: block;
    white-space: pre-wrap;
}

#studyAnswer {
    margin-top: 32px;
    padding-top: 32px;
    border-top: 1px solid var(--line);
    font-family: var(--font-body);
    font-size: clamp(16px, 2vw, 20px);
    line-height: 1.7;
}

.study-actions {
    justify-content: center;
    margin-top: 28px;
}

.study-actions button {
    min-width: 110px;
}

.shortcut-hint {
    margin: 24px 0 0;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

/* Keep the sidebar visible and controls usable on smaller screens. */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 184px;
    }

    .sidebar {
        padding: 36px 20px;
    }

    .sidebar h1 {
        margin-left: 12px;
        font-size: 23px;
    }

    .main-content {
        padding: 48px 32px 72px;
    }

    #homeView header {
        max-width: 100%;
    }

    .jellyfish-swimmer {
        right: -8%;
        width: 90%;
    }

    .jellyfish-swimmer[data-view="homeView"] {
        --art-opacity: 0.45;
    }
}

@media (max-width: 600px) {
    :root {
        --sidebar-width: 108px;
    }

    body {
        font-size: 14px;
    }

    .sidebar {
        padding: 28px 10px;
    }

    .sidebar h1 {
        margin: 0 0 56px 4px;
        font-size: 19px;
    }

    .nav-button {
        padding: 14px 8px;
    }

    .nav-button [lang="ja"] {
        font-size: 18px;
    }

    .nav-translation {
        font-size: 10px;
    }

    .main-content {
        padding: 32px 20px 56px;
    }

    #homeView header {
        margin-top: 8px;
    }

    #homeView {
        min-height: 0;
    }

    .jellyfish-swimmer {
        top: 48px;
        right: -90px;
        width: 320px;
        height: 500px;
    }

    .jellyfish-swimmer[data-view="homeView"] {
        --art-opacity: 0.3;
    }

    .recent-deck-panel {
        margin-top: 36px;
        padding: 16px;
    }

    .japanese-heading {
        font-size: 28px;
    }

    #homeView header h2 {
        font-size: 13px;
    }

    .deck,
    .folder {
        padding: 20px;
    }

    .section-heading {
        margin-bottom: 36px;
    }

    .library-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    #deckFolderSelect {
        display: block;
        width: 100%;
        margin: 8px 0 0;
    }

    #importFile::file-selector-button {
        display: block;
        margin-bottom: 8px;
    }

    #studyCard {
        min-height: 260px;
    }

    .study-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .jellyfish-drift,
    .jellyfish-image {
        animation: none;
    }

    #jellyfishTwo .jellyfish-image {
        transform: scaleX(-1);
    }
}
