:root {
    --surface: rgba(15, 23, 42, 0.85);
    --border: rgba(148, 163, 184, 0.3);
    --text-muted: #cbd5f5;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
    background-color: #020617;
    color: #f8fafc;
    height: 100vh; /* min-height から height に変更して画面内に収める */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 全体スクロールを抑制 */
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: rgba(15, 23, 42, 0.6);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

header h1 {
    font-size: 1.25rem;
    margin: 0;
    white-space: nowrap;
}

.amazon-associate {
    font-size: 0.7rem;
    color: rgba(148, 163, 184, 0.5);
    margin: 0;
    text-align: right;
    line-height: 1.3;
}

main {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1.5rem;
    padding: 1rem 1.5rem 1.5rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.sidebar-banner {
    display: block;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.sidebar-banner:hover {
    opacity: 0.9;
}

.sidebar-banner img {
    display: block;
    width: 100%;
    height: auto;
}

.article-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 12px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 600;
}

.article-link:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.article-link__icon {
    color: var(--accent);
    display: flex;
    align-items: center;
}

.article-link__text {
    flex: 1;
}

.article-link__arrow {
    color: var(--accent);
    opacity: 0.7;
    transition: transform 0.2s;
}

.article-link:hover .article-link__arrow {
    transform: translateX(2px);
    opacity: 1;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
    overflow: hidden;
}

section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    position: relative;
}

.preview-overlay-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
    display: flex;
    gap: 8px;
}

.theater-btn {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.4);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.theater-btn.active {
    background: var(--accent);
    color: #0f172a;
    border-color: var(--accent);
}

.theater-btn:hover {
    background: var(--accent);
    color: #0f172a;
    border-color: var(--accent);
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: -12px;
    left: 0;
    right: 0;
    height: 24px;
    cursor: row-resize;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: none;
}

.resize-handle:hover,
.resize-handle.active {
    opacity: 1;
}

.resize-handle-bar {
    width: 48px;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

/* Theater Mode adjustments for resize handle */
body.theater-mode .resize-handle {
    display: none;
}

/* Theater Mode */
body.theater-mode .sidebar {
    display: none;
}

body.theater-mode .list {
    display: none;
}

body.theater-mode header,
body.theater-mode footer,
body.theater-mode .view-mode-header {
    display: none !important;
}

body.theater-mode main {
    grid-template-columns: 1fr;
    height: 100vh;
}

body.theater-mode .preview {
    height: 100% !important;
    flex: 1 !important;
}

.list {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

h1, h2 {
    margin: 0 0 0.5rem;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.collapsible-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.collapsible-toggle {
    width: 100%;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0;
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    font-weight: 600;
    text-align: left;
}


.collapsible-toggle__icon {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 9px;
    border-color: transparent transparent transparent currentColor;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.collapsible-toggle[aria-expanded="true"] .collapsible-toggle__icon {
    transform: rotate(90deg);
}

.collapsible-toggle__text {
    font-size: 0.95rem;
}

.collapsible-content {
    margin-top: 0.75rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.button-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.preset-panel {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
}

.preset-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

.preset-actions {
    display: flex;
    gap: 0.5rem;
}

#presetSelect {
    flex: 1;
    min-width: 0;
    background: rgba(15, 23, 42, 0.8);
    border-color: rgba(148, 163, 184, 0.5);
}

.btn-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.55rem 1.2rem;
    background: var(--accent);
    color: #0f172a;
    font-weight: 700;
    border-radius: 6px;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.btn-add:hover {
    background: var(--accent-strong);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.btn-add:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-add:disabled {
    background: rgba(148, 163, 184, 0.2);
    color: rgba(148, 163, 184, 0.5);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn-add svg {
    display: block;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

input, select, button {
    padding: 0.55rem 0.6rem;
    border-radius: 6px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    font-size: 0.95rem;
    background: rgba(15, 23, 42, 0.6);
    color: inherit;
}

input[type="color"] {
    padding: 0.2rem;
    background: transparent;
    height: 42px;
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

button {
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: #02101f;
    font-weight: 600;
    transition: background 0.2s ease;
}

button:hover {
    background: var(--accent-strong);
}

.import-label {
    display: inline-flex;
    align-items: center;
    padding: 0.55rem 0.9rem;
    border-radius: 6px;
    border: 1px dashed rgba(148, 163, 184, 0.6);
    cursor: pointer;
}

.import-label:hover {
    border-color: #f8fafc;
}

#importInput {
    display: none;
}

.data-note {
    margin: 0.75rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

#canvasContainer {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
    display: grid;
}

.spec-rect {
    position: relative;
    grid-area: 1 / 1;
    border: 2px solid currentColor;
    border-radius: 10px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 0.5rem;
    color: inherit;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.spec-rect:active {
    cursor: grabbing;
}

.spec-rect::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0.08;
    pointer-events: none;
}

.spec-rect__label {
    position: absolute;
    z-index: 1;
    font-size: 0.8rem;
    line-height: 1.2;
    background: rgba(0, 0, 0, 0.35);
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: auto;
}

.spec-rect__label:active {
    cursor: grabbing;
}

.watermark {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11%; /* 面積比約1.25% (以前の1/4) */
    height: auto;
    opacity: 0.2;
    pointer-events: none;
    z-index: 100;
}

.spec-rect__label-name {
    font-weight: 600;
    letter-spacing: 0.01em;
    margin-right: 0.4em;
}

.spec-rect__label-meta {
    font-size: 0.75rem;
    color: #e2e8f0;
}

.spec-rect.label-pos-top-left .spec-rect__label {
    top: 6px;
    left: 6px;
}

.spec-rect.label-pos-top-right .spec-rect__label {
    top: 6px;
    right: 6px;
}

.spec-rect.label-pos-bottom-left .spec-rect__label {
    bottom: 6px;
    left: 6px;
}

.spec-rect.label-pos-bottom-right .spec-rect__label {
    bottom: 6px;
    right: 6px;
}

.spec-rect.label-pos-mid-left .spec-rect__label {
    top: 50%;
    left: 6px;
    transform: translateY(-50%);
}

.spec-rect.label-pos-mid-right .spec-rect__label {
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
}

.spec-label-container {
    position: relative;
    grid-area: 1 / 1;
    pointer-events: none;
    /* Ensure it matches spec-rect layout behavior */
    display: block; 
}

.anchor-center {
    place-self: center;
}

.anchor-bottom-left {
    place-self: end start;
}

/* Anchor Grid Selector */
.anchor-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 6px;
    padding: 4px;
}

.anchor-grid button {
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.anchor-grid button:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.3);
}

.anchor-grid button[aria-checked="true"] {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

/* Anchor Positions */
.anchor-top-left { place-self: start start; }
.anchor-top-center { place-self: start center; }
.anchor-top-right { place-self: start end; }
.anchor-mid-left { place-self: center start; }
.anchor-center { place-self: center center; }
.anchor-mid-right { place-self: center end; }
.anchor-bottom-left { place-self: end start; }
.anchor-bottom-center { place-self: end center; }
.anchor-bottom-right { place-self: end end; }

#specList {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    width: 100%;
    padding: 0;
    margin: 0;
}

.spec-table {
    width: 100%;
    border-collapse: separate; /* Changed from collapse to allow row borders/spacing */
    border-spacing: 0 0.5rem;
    min-width: 560px;
}

.spec-table th,
.spec-table td {
    text-align: left;
    padding: 0.45rem 0.6rem;
    /* border-bottom: 1px solid rgba(148, 163, 184, 0.25); Removed for card style */
    white-space: nowrap;
}

.spec-table th {
    border-bottom: 1px solid rgba(148, 163, 184, 0.25); /* Keep header separator */
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-bottom: 0.75rem;
    position: sticky;
    top: 0;
    background: var(--surface); /* 背景色がないと透ける */
    z-index: 2;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.spec-table tbody tr td {
    background-color: var(--row-bg);
    border-top: 2px solid var(--row-color);
    border-bottom: 2px solid var(--row-color);
}

.spec-table tbody tr td:first-child {
    border-left: 2px solid var(--row-color);
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.spec-table tbody tr td:last-child {
    border-right: 2px solid var(--row-color);
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

.spec-table tbody tr:hover {
    filter: brightness(1.2);
}

.spec-table__sort {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.spec-table__sort:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.spec-table__sort-indicator {
    font-size: 0.75rem;
    opacity: 0.8;
}

.spec-table th[data-sort-disabled="true"] {
    opacity: 0.6;
}

.spec-table tbody tr:hover {
    background: rgba(148, 163, 184, 0.08);
}

.spec-table__color-picker {
    border: none;
    background: none;
    width: 28px;
    height: 28px;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

.spec-table__color-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: rgba(148, 163, 184, 0.2);
}

.spec-table__color {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.spec-table__color-chip::before {
    content: "";
    display: block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: currentColor;
}

.spec-table__actions button {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.spec-empty {
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.field-error {
    margin: 0.25rem 0 0;
    font-size: 0.8rem;
    color: #fca5a5;
    min-height: 1em;
}

.field-error[hidden] {
    display: none;
}

.input-error {
    border-color: #f87171 !important;
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.4);
}

.settings-separator {
    border: 0;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    margin: 1.5rem 0;
}

.calc-note {
    margin: 0.5rem 0 0;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.25);
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.spec-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
}

.spec-item__meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.spec-item__title {
    font-weight: 600;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: rgba(148, 163, 184, 0.2);
}

.chip::before {
    content: "";
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: currentColor;
}

footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    background: rgba(15, 23, 42, 0.6);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--accent);
}

.share-area {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.share-area button {
    width: 100%;
    background: #0ea5e9;
    color: white;
    font-weight: bold;
    padding: 0.75rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.share-area button:hover {
    background: #0284c7;
}

.share-area button:disabled {
    background: rgba(148, 163, 184, 0.2);
    color: rgba(148, 163, 184, 0.5);
    cursor: not-allowed;
    box-shadow: none;
}

.view-mode-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.btn-twitter {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #000;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    border-radius: 6px;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-twitter:hover {
    background: #333;
}

.btn-twitter svg {
    display: block;
}

.spec-table__header-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.spec-table__header-btn:hover {
    color: var(--accent);
    background: rgba(148, 163, 184, 0.1);
}

.spec-table tr.dragging {
    opacity: 0.4;
    background: rgba(56, 189, 248, 0.1) !important;
}

.spec-table tr[draggable="true"] {
    cursor: grab;
}

.spec-table tr[draggable="true"]:active {
    cursor: grabbing;
}

@media (max-width: 768px) {
    body {
        height: auto;
        overflow: auto;
    }

    main {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        overflow: visible;
        padding: 0.5rem;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.75rem 1rem;
        gap: 0.25rem;
    }

    header h1 {
        font-size: 1.1rem;
        white-space: normal;
    }

    .amazon-associate {
        text-align: left;
        font-size: 0.65rem;
    }

    .sidebar {
        overflow-y: visible;
        padding-right: 0;
        min-width: 0;
    }

    .main-content {
        overflow-y: visible;
        height: auto;
        min-width: 0;
    }

    section {
        padding: 0.75rem;
    }

    .preview {
        min-height: 0;
        flex: none;
    }

    .list {
        flex: none;
        max-height: 60vh;
    }

    #canvasContainer {
        min-height: 240px;
        flex: none;
        height: auto;
        aspect-ratio: 3/2;
    }

    .controls {
        grid-column: span 1;
    }

    .spec-rect__label {
        font-size: 0.7rem;
    }
}

/* View Mode */
body.view-mode .sidebar {
    display: none;
}

body.view-mode .main-content {
    grid-column: 1 / -1;
}

body.view-mode .spec-table__actions,
body.view-mode .spec-table th:last-child {
    display: none;
}

body.view-mode .spec-table__color-picker {
    pointer-events: none;
    opacity: 0.8;
}

.view-mode-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    margin-bottom: 0.5rem;
    color: #e0f2fe;
}

body.view-mode .view-mode-header {
    display: flex;
}

.view-mode-header p {
    margin: 0;
    font-weight: 600;
}

.view-mode-header button {
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    background: rgba(56, 189, 248, 0.2);
    border: 1px solid rgba(56, 189, 248, 0.4);
    color: #e0f2fe;
}

.view-mode-header button:hover {
    background: rgba(56, 189, 248, 0.3);
}

#exitViewModeBtn {
    padding: 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
}

body.view-mode .spec-table tbody tr td:nth-last-child(2) {
    border-right: 2px solid var(--row-color);
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

.spec-name-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.amazon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #f97316; /* Amazon Orange */
    opacity: 0.7;
    transition: all 0.2s;
    padding: 4px;
    border-radius: 4px;
    background: rgba(249, 115, 22, 0.1);
}

.amazon-link:hover {
    opacity: 1;
    background: rgba(249, 115, 22, 0.2);
    transform: translateY(-1px);
}

.amazon-link svg {
    width: 14px;
    height: 14px;
}


/* Highlight Interaction */
#canvasContainer.has-highlight .spec-rect,
#canvasContainer.has-highlight .spec-label-container {
    transition: opacity 0.2s, transform 0.2s;
}

#canvasContainer.has-highlight .spec-rect:not(.highlighted),
#canvasContainer.has-highlight .spec-label-container:not(.highlighted) {
    opacity: 0.3;
}

.spec-rect.highlighted {
    z-index: 50;
    box-shadow: 0 0 0 2px currentColor, 0 0 25px rgba(0, 0, 0, 0.6);
}

.spec-label-container.highlighted {
    z-index: 51;
}

.spec-table tbody tr.highlighted {
    background: rgba(56, 189, 248, 0.15) !important;
    filter: brightness(1.2);
}

