:root {
    --bg-color: #fcfcfc;
    --text-main: #222222;
    --text-sub: #888888;
    --accent: #444444;
    --line: #e0e0e0;
    --font-serif: 'Shippori Mincho', serif;
    --font-sans: 'Zen Kaku Gothic New', sans-serif;
    --font-title: 'Hina Mincho', serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-sans);
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    min-height: 100vh;
}

.screen {
    position: relative;
    width: 100%;
    display: none;
    flex-direction: column;
    padding: 2rem;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#screen-top {
    padding-top: 8rem;
    /* 設定ボタンと吹き出しを避けるための余白 */
}

.screen.active {
    display: flex;
    opacity: 1;
    z-index: 10;
}

/* Common Layouts */
.center-content {
    flex-grow: 1;
    /* Allow growing */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 100%;
    /* Ensure full height for centering */
    width: 100%;
}

.header-minimal {
    padding-bottom: 1rem;
}

/* Typography */
.app-title {
    font-family: var(--font-title);
    font-size: 3.9rem;
    /* 130% of original 3rem */
    font-weight: 400;
    /* Hina Mincho is elegant at regular weight */
    letter-spacing: 0.2rem;
    margin-bottom: 1rem;
}

.app-title ruby rt {
    font-size: 0.15em;
    /* Reduced to approx 60% of previous 0.25em */
    letter-spacing: 0.1rem;
    font-family: var(--font-sans);
    /* Use sans-serif for clarity in small size */
    opacity: 0.7;
    margin-bottom: 0.5em;
    /* Add space between ruby and base text (approx half of ruby size) */
    display: block;
    /* Ensure margin-bottom works well in some browsers */
}

.app-subtitle {
    font-family: var(--font-title);
    font-size: 0.9rem;
    color: var(--text-sub);
    margin-bottom: 3rem;
    letter-spacing: 0.05rem;
}

/* Buttons */
.btn-primary {
    background: var(--text-main);
    color: #fff;
    border: none;
    padding: 0.8rem 2.5rem;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    font-family: var(--font-sans);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Removed dynamic button color per user request */
#btn-generate {
    transition: transform 0.2s, opacity 0.2s;
}

.btn-secondary {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--text-main);
    padding: 0.6rem 2rem;
    font-size: 0.9rem;
    border-radius: 50px;
    cursor: pointer;
    margin: 0.5rem;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #f0f0f0;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-sub);
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-text:hover {
    color: var(--text-main);
}

.top-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* Input Screen */
.scroll-content {
    padding-bottom: 2rem;
}

.step-group {
    margin-bottom: 2rem;
}

.questions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.btn-text-icon {
    background: none;
    border: none;
    color: var(--text-sub);
    /* Match step-label color */
    font-size: 0.8rem;
    /* Match step-label size */
    font-family: inherit;
    /* Inherit font family */
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    opacity: 0.8;
    /* Match instruction-msg opacity concept if needed, or just keep simple */
}

.btn-text-icon:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.step-label {
    font-size: 0.8rem;
    color: var(--text-sub);
    margin-bottom: 1rem;
    display: block;
}

.tone-selector {
    display: flex;
    flex-wrap: nowrap;
    /* Force single row */
    gap: 0.3rem;
    /* Reduced gap to fit 6 items */
    margin-bottom: 2rem;
    width: 100%;
}

.tone-option {
    flex: 1;
    /* Distribute space evenly */
    min-width: 0;
    /* Allow shrinking */
}

.tone-option input {
    display: none;
}

.badget {
    display: block;
    /* Change to block for flex even width */
    width: 100%;
    padding: 0.4rem 0.2rem;
    /* Reduced horizontal padding */
    border: 1px solid var(--line);
    border-radius: 20px;
    font-size: 0.75rem;
    /* Slightly smaller font to fit */
    text-align: center;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tone-desc {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-sub);
    min-height: 1.2rem;
    /* Prevent layout jump */
    font-family: var(--font-sans);
}

.tone-option input:checked+.badget {
    background: var(--text-main);
    color: #fff;
    border-color: var(--text-main);
}

.question-card {
    margin-bottom: 2.5rem;
}

.question-text {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
    font-family: var(--font-serif);
}

.input-line {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--line);
    padding: 0.5rem 0;
    font-size: 1rem;
    background: transparent;
    border-radius: 0;
    transition: border-color 0.3s;
}

.input-line:focus {
    outline: none;
    border-color: var(--text-main);
}

.input-area {
    width: 100%;
    min-height: 100px;
    border: 1px solid var(--line);
    padding: 0.8rem;
    font-size: 1rem;
    font-family: var(--font-sans);
    background: transparent;
    border-radius: 4px;
    resize: none;
    transition: border-color 0.3s;
}

.input-area:focus {
    outline: none;
    border-color: var(--text-main);
}

.action-area {
    text-align: center;
    margin-top: 2rem;
}

/* Output Screen */
#screen-output {
    padding: 6rem 2rem;
}

.paper-display {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 1.5rem;
    /* Reduced bottom margin from 3rem */
    padding: 2rem;
    background: #fff;
    /* Plain white paper */
    border: 1px solid #f0f0f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
    text-align: left;
    writing-mode: horizontal-tb;
    /* Default to horizontal */
}

/* Removed vertical writing mode per user request to maximize space */
/* 
.paper-display.vertical {
    writing-mode: vertical-rl;
    height: 400px;
    overflow-x: auto;
}
*/

.paper-text {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    line-height: 2.2;
    white-space: pre-wrap;
}

.action-buttons {
    display: flex;
    flex-direction: row;
    /* Changed to horizontal per user request */
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

/* History Screen */
.screen-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 400;
    margin-left: 1rem;
}

.history-item {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.history-date {
    font-size: 0.8rem;
    color: var(--text-sub);
    margin-bottom: 0.5rem;
}

.history-preview {
    font-size: 0.95rem;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.6;
}

.history-empty {
    text-align: center;
    color: var(--text-sub);
    margin-top: 4rem;
}

/* Loading Animation */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

/* Settings & Modal */
.settings-area {
    position: absolute;
    top: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    z-index: 20;
}

.settings-guide {
    position: relative;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    font-size: 0.65rem;
    /* ~80% of 0.75rem or 0.8rem */
    color: var(--text-main);
    text-align: left;
    max-width: 240px;
    /* Wider to fit 3 lines */
    line-height: 1.5;
    pointer-events: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    margin-bottom: 0.5rem;
    /* Slowed down animation (half speed) */
    animation: bounce 4s infinite ease-in-out;
}

/* Speech bubble tail (border) */
.settings-guide::before {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 12px;
    border-width: 10px 10px 0 0;
    border-style: solid;
    border-color: var(--line) transparent transparent transparent;
}

/* Speech bubble tail (background) */
.settings-guide::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 13px;
    border-width: 9px 9px 0 0;
    border-style: solid;
    border-color: #fff transparent transparent transparent;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.settings-icon {
    color: var(--text-sub);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.3s;
}

.settings-icon:hover {
    color: var(--text-main);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: #fff;
    width: 90%;
    max-width: 400px;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-card {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: normal;
}

.close-icon {
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-sub);
}

.modal-body {
    margin-bottom: 2rem;
}

.label-heading {
    display: block;
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.modal-desc {
    font-size: 0.8rem;
    color: var(--text-sub);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.api-links {
    margin-top: 0.5rem;
    text-align: right;
}

.api-links a {
    font-size: 0.8rem;
    color: var(--text-sub);
    text-decoration: underline;
}

.input-line[type="password"] {
    letter-spacing: 0.2rem;
}

.modal-footer {
    text-align: right;
}

.show-top-margin {
    margin-top: 1.5rem;
}

.instruction-msg {
    font-size: 0.8rem;
    color: var(--text-sub);
    margin-bottom: 2rem;
    opacity: 0.8;
}

.mock-warning {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--text-sub);
    border-top: 1px dashed var(--line);
    padding-top: 1rem;
    text-align: center;
}

.api-test-area {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-small {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
}

.status-msg {
    font-size: 0.8rem;
    transition: color 0.3s;
}

.status-msg.success {
    color: #4caf50;
}

.status-msg.error {
    color: #f44336;
}

/* Footer */
.app-footer {
    margin-top: auto;
    padding-top: 2rem;
    padding-bottom: 2rem;
    text-align: center;
}

.privacy-note {
    font-size: 0.65rem;
    /* Match .settings-guide size */
    color: var(--text-sub);
    /* Match gray text */
    margin-bottom: 0.4rem;
    opacity: 0.8;
}

.copyright {
    font-size: 0.65rem;
    /* Match .settings-guide size */
    color: var(--text-sub);
    /* Match gray text */
    letter-spacing: 0.05rem;
}