/* ============================================================
   三國志真戦 メッセージフォーマッター — CSS
   ============================================================ */

/* --- Design Tokens --- */
:root {
    /* Backgrounds */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111729;
    --bg-card: rgba(16, 22, 40, 0.92);
    --bg-input: rgba(10, 14, 26, 0.8);
    --bg-toolbar: rgba(20, 28, 50, 0.95);
    --bg-hover: rgba(212, 168, 83, 0.08);

    /* Gold Accent */
    --gold: #d4a853;
    --gold-light: #e8c068;
    --gold-dim: rgba(212, 168, 83, 0.35);
    --gold-glow: rgba(212, 168, 83, 0.15);

    /* Game Colors */
    --color-blue: #5eaaff;
    --color-green: #5eff8a;
    --color-red: #ff5e5e;
    --color-yellow: #ffe066;

    /* Text */
    --text-primary: #e8e0d0;
    --text-secondary: #9a9494;
    --text-muted: #5a5656;

    /* Borders */
    --border: rgba(212, 168, 83, 0.18);
    --border-focus: rgba(212, 168, 83, 0.5);

    /* Radius */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    /* Shadows */
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(212, 168, 83, 0.1);

    /* Font */
    --font-main: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
    --font-mono: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;

    /* Transition */
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(212, 168, 83, 0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(94, 170, 255, 0.03) 0%, transparent 60%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--gold-dim);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--gold);
}

/* --- Header --- */
.site-header {
    text-align: center;
    padding: 48px 20px 32px;
    position: relative;
}

.site-header::after {
    content: '';
    display: block;
    width: 120px;
    height: 2px;
    margin: 24px auto 0;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.site-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 50%, #c0943a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
}

.site-subtitle {
    display: block;
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    opacity: 0.9;
}

.site-desc {
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

/* --- Main Layout --- */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* --- Color Reference Bar --- */
.color-ref {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.ref-item {
    font-size: 0.82rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.ref-symbol {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.85rem;
}

.ref-blue { color: var(--color-blue); }
.ref-green { color: var(--color-green); }
.ref-red { color: var(--color-red); }
.ref-yellow { color: var(--color-yellow); }

/* --- Panel (Shared) --- */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-toolbar);
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 0.05em;
}

/* --- Editor Container (2-col) --- */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    white-space: nowrap;
}

.tool-btn:hover {
    background: var(--bg-hover);
    border-color: var(--gold-dim);
}

.tool-btn:active {
    transform: scale(0.95);
}

/* Color Dot */
.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Color Button Variants */
.color-btn.blue .color-dot { background: var(--color-blue); box-shadow: 0 0 6px var(--color-blue); }
.color-btn.green .color-dot { background: var(--color-green); box-shadow: 0 0 6px var(--color-green); }
.color-btn.red .color-dot { background: var(--color-red); box-shadow: 0 0 6px var(--color-red); }
.color-btn.yellow .color-dot { background: var(--color-yellow); box-shadow: 0 0 6px var(--color-yellow); }

.color-btn.blue:hover { border-color: var(--color-blue); background: rgba(94, 170, 255, 0.1); }
.color-btn.green:hover { border-color: var(--color-green); background: rgba(94, 255, 138, 0.1); }
.color-btn.red:hover { border-color: var(--color-red); background: rgba(255, 94, 94, 0.1); }
.color-btn.yellow:hover { border-color: var(--color-yellow); background: rgba(255, 224, 102, 0.1); }

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

/* Confirming state for clear button */
.tool-btn.confirming {
    border-color: var(--color-red);
    background: rgba(255, 94, 94, 0.15);
    color: var(--color-red);
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 94, 94, 0.3); }
    50% { box-shadow: 0 0 8px 2px rgba(255, 94, 94, 0.15); }
}

/* --- Editor Textarea --- */
.editor-body {
    padding: 0;
}

#editor {
    width: 100%;
    min-height: 300px;
    padding: 20px;
    border: none;
    outline: none;
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.8;
    resize: vertical;
    caret-color: var(--gold);
    tab-size: 4;
}

#editor::placeholder {
    color: var(--text-muted);
    font-family: var(--font-main);
}

#editor:focus {
    background: rgba(12, 16, 30, 0.95);
}

.char-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* --- Preview Panel --- */
.preview-frame {
    position: relative;
    margin: 16px;
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius-sm);
    background: #0d0d0d;
    min-height: 260px;
    overflow: hidden;
}

/* Corner ornaments */
.preview-frame::before,
.preview-frame::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-style: solid;
    border-color: var(--gold);
    z-index: 1;
}

.preview-frame::before {
    top: -1px;
    left: -1px;
    border-width: 2px 0 0 2px;
    border-radius: 3px 0 0 0;
}

.preview-frame::after {
    bottom: -1px;
    right: -1px;
    border-width: 0 2px 2px 0;
    border-radius: 0 0 3px 0;
}

.preview-content {
    padding: 20px 24px;
    font-size: 0.92rem;
    line-height: 1.9;
    color: var(--text-primary);
    word-break: break-all;
    overflow-wrap: break-word;
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
}

/* Preview color classes (XSS-safe: used via className, not inline style) */
.color-blue { color: var(--color-blue); }
.color-green { color: var(--color-green); }
.color-red { color: var(--color-red); }
.color-yellow { color: var(--color-yellow); }

/* Additional corner ornaments via extra elements */
.corner-tr,
.corner-bl {
    position: absolute;
    width: 16px;
    height: 16px;
    border-style: solid;
    border-color: var(--gold);
    z-index: 1;
    pointer-events: none;
}
.corner-tr {
    top: -1px;
    right: -1px;
    border-width: 2px 2px 0 0;
    border-radius: 0 3px 0 0;
}
.corner-bl {
    bottom: -1px;
    left: -1px;
    border-width: 0 0 2px 2px;
    border-radius: 0 0 0 3px;
}

/* --- Output Panel --- */
.output-panel {
    margin-bottom: 20px;
}

.output-body {
    padding: 16px 20px;
    background: var(--bg-input);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.8;
    color: var(--text-primary);
    word-break: break-all;
    overflow-wrap: break-word;
    min-height: 60px;
    white-space: pre-wrap;
    user-select: all;
}

/* --- Action Buttons --- */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 16px;
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius-xs);
    background: rgba(212, 168, 83, 0.08);
    color: var(--gold);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.action-btn:hover {
    background: rgba(212, 168, 83, 0.18);
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(212, 168, 83, 0.12);
}

.action-btn:active {
    transform: scale(0.96);
}

/* --- Messages Panel --- */
.messages-panel {
    margin-bottom: 40px;
}

.save-form {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

#messageTitle {
    flex: 1;
    min-width: 200px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
}

#messageTitle:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

#messageTitle::placeholder {
    color: var(--text-muted);
}

.save-btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-xs);
    background: linear-gradient(135deg, var(--gold) 0%, #c0943a 100%);
    color: #0a0e1a;
    font-family: var(--font-main);
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.save-btn:hover {
    background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 100%);
    box-shadow: 0 4px 16px rgba(212, 168, 83, 0.25);
    transform: translateY(-1px);
}

.save-btn:active {
    transform: translateY(0) scale(0.98);
}

.new-btn {
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.new-btn:hover {
    background: var(--bg-hover);
    border-color: var(--gold-dim);
}

.hidden {
    display: none !important;
}

/* --- Messages List --- */
.messages-list {
    padding: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.messages-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.message-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    transition: var(--transition);
}

.message-card:last-child {
    margin-bottom: 0;
}

.message-card:hover {
    background: var(--bg-hover);
    border-color: var(--gold-dim);
}

.message-card.active {
    border-color: var(--gold);
    background: var(--gold-glow);
}

.message-info {
    flex: 1;
    min-width: 0;
}

.message-title-text {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.message-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 12px;
}

.msg-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.msg-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.msg-btn.load-btn:hover {
    border-color: var(--color-blue);
    color: var(--color-blue);
}

.msg-btn.delete-btn:hover {
    border-color: var(--color-red);
    color: var(--color-red);
}

.msg-btn.delete-btn.confirming {
    border-color: var(--color-red);
    background: rgba(255, 94, 94, 0.15);
    color: var(--color-red);
    animation: pulse-red 1s infinite;
}

/* --- Toast Notification --- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    padding: 12px 28px;
    background: rgba(16, 22, 40, 0.95);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    border-color: var(--color-red);
    background: rgba(40, 12, 12, 0.95);
}

/* --- Copy feedback --- */
.copy-feedback {
    animation: copy-flash 0.6s ease;
}

@keyframes copy-flash {
    0% { box-shadow: 0 0 0 0 rgba(94, 255, 138, 0.4); }
    50% { box-shadow: 0 0 12px 4px rgba(94, 255, 138, 0.15); }
    100% { box-shadow: none; }
}

/* --- Clipboard helper (offscreen) --- */
.offscreen-textarea {
    position: fixed;
    opacity: 0;
    left: -9999px;
    top: -9999px;
}

/* --- Responsive --- */
@media (max-width: 820px) {
    .editor-container {
        grid-template-columns: 1fr;
    }

    .site-header {
        padding: 32px 16px 24px;
    }

    .site-title {
        font-size: 1.6rem;
    }

    .toolbar {
        gap: 6px;
        padding: 8px 12px;
    }

    .tool-btn {
        padding: 5px 10px;
        font-size: 0.78rem;
    }

    #editor {
        min-height: 200px;
    }

    .preview-frame {
        margin: 12px;
        min-height: 180px;
    }

    .color-ref {
        gap: 12px;
        padding: 10px 14px;
    }

    .ref-item {
        font-size: 0.75rem;
    }

    .save-form {
        flex-direction: column;
    }

    .save-form .save-btn,
    .save-form .new-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 1.3rem;
    }

    .color-ref {
        gap: 8px;
    }

    .ref-item {
        font-size: 0.7rem;
    }

    .message-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .message-actions {
        margin-left: 0;
        width: 100%;
    }

    .msg-btn {
        flex: 1;
        text-align: center;
        justify-content: center;
    }
}

/* --- Fade-in animation for cards --- */
@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-card {
    animation: fade-in-up 0.3s ease forwards;
}
