:root {
    /* Colors */
    --bg-color: #0d0d0d;
    --text-color: #ffffff;
    --text-muted: #8e8e93;
    --bubble-bg: #00B900;
    /* LINE Greenish */
    --bubble-text: #ffffff;
    --header-bg: #0d0d0d;
    --input-bg: #1c1c1e;
    --border-color: #333;
    --modal-bg: #1c1c1e;
    --primary-color: #007aff;
    /* iOS Blue */
    --danger-color: #ff3b30;
    --control-bg: #2c2c2e;
    --control-active: #007aff;

    /* Font Sizes */
    --fs-sm: 12px;
    --fs-md: 15px;
    --fs-lg: 18px;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

/* Light Theme overrides */
body.theme-light {
    --bg-color: #ffffff;
    --text-color: #000000;
    --text-muted: #8e8e93;
    --bubble-bg: #8DE055;
    /* Lighter Green */
    --bubble-text: #000000;
    --header-bg: #f9f9f9;
    --input-bg: #f0f0f0;
    --border-color: #ddd;
    --modal-bg: #ffffff;
    --control-bg: #eeeeee;
}

/* Font Size Scaling */
body.font-sm {
    font-size: 14px;
}

body.font-md {
    font-size: 16px;
}

body.font-lg {
    font-size: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: block;
    /* Removed flex since we are fixing footer */
    overflow: hidden;
    /* Keep hidden but we might handle scroll differently */
}

/* Header */
.app-header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--spacing-md);
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Main Chat Area */
#chat-container {
    /* flex: 1; Removed flex since footer is fixed/absolute */
    height: calc(100vh - 60px);
    /* Subtract header height */
    overflow-y: auto;
    padding: var(--spacing-md);
    padding-bottom: 80px;
    /* Space for fixed footer */
    display: flex;
    flex-direction: column;
    /* Basic scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: var(--spacing-lg) 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    position: relative;
}

/* Message Row Structure - KEY REQUIREMENT */
.message-row {
    display: flex;
    justify-content: flex-end;
    /* Align all content to right */
    align-items: flex-end;
    /* Align items at bottom */
    margin-bottom: var(--spacing-sm);
    gap: 6px;
}

.bubble {
    background-color: var(--bubble-bg);
    color: var(--bubble-text);
    padding: 10px 14px;
    border-radius: 18px;
    border-top-right-radius: 4px;
    /* Slight customization for right alignment styling */
    max-width: 75%;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
    position: relative;
    cursor: context-menu;
    user-select: text;
    user-select: none;
    /* Prevent text selection to make clicking easier */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: opacity 0.2s, text-decoration 0.2s;

    /* Ensure bubble is rightmost */
    order: 2;
}

.bubble.done {
    text-decoration: line-through;
    color: rgba(255, 255, 255, 0.6);
    background-color: var(--bubble-bg);
    /* Keep bg but maybe desaturate via opacity or just trust the text color change? */
    opacity: 0.7;
}

/* Light mode adjustment for done state */
body.theme-light .bubble.done {
    color: rgba(0, 0, 0, 0.5);
}

.timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-bottom: 2px;
    /* Slight adjustment to align with text baseline roughly */
    user-select: none;

    /* Ensure timestamp is to the LEFT of bubble */
    order: 1;
}

/* Footer Input */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    padding: var(--spacing-md);
    background-color: var(--header-bg);
    /* Use same as header roughly */
    border-top: 1px solid var(--border-color);
    /* flex-shrink: 0; not needed for fixed */
}

.input-container {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-end;
    background-color: var(--input-bg);
    border-radius: 20px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 8px 0;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
}

#send-btn {
    background-color: var(--primary-color);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    margin-bottom: 2px;
}

#send-btn:hover {
    filter: brightness(1.1);
}

/* Modals */
.hidden {
    display: none !important;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    z-index: 1001;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    margin-bottom: 24px;
    font-size: 1.2rem;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-label {
    margin-bottom: 8px;
    font-weight: 500;
}

.segmented-control {
    display: flex;
    background-color: var(--control-bg);
    border-radius: 8px;
    padding: 2px;
}

.segmented-control button {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.segmented-control button.active {
    background-color: var(--control-active);
    color: white;
}

.setting-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.4;
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

/* Context Menu */
#context-menu {
    position: absolute;
    background-color: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
}

.ctx-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.text-danger {
    color: var(--danger-color);
}

/* Adjustments for buttons inside controls */
.segmented-control button.active[data-value="light"],
.segmented-control button.active[data-value="auto"],
.segmented-control button.active[data-value="dark"] {
    /* Ensure active state is visible */
}

/* Ensure font sizes affect chat */
body.font-sm .bubble {
    font-size: 13px;
}

body.font-lg .bubble {
    font-size: 18px;
}