/* 全画面共通のスタイル。アイコンの画像と寸法は board.js がCSS変数で渡します。 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --cell-width: 30px;
    --cell-height: 35px;
    --text-cell-width: 89px;
    --blue: #2196F3;
    --green: #4CAF50;
    --red: #f44336;
}

body {
    font-family: 'Arial', sans-serif;
    padding: 20px;
    background-color: #f5f5f5;
    color: #333;
    min-height: 100vh;
}

.container { text-align: center; }
h1 { margin-bottom: 10px; font-size: 26px; }
.subtitle { color: #666; font-size: 14px; margin-bottom: 16px; }

.panel {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 15px;
}

.row {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
.row > label, .label { color: #666; font-size: 14px; font-weight: bold; }
.divider { border-left: 1px solid #ddd; padding-left: 15px; }
.muted { color: #888; font-size: 13px; }

/* ---- ボタン・入力 ---- */
.btn {
    padding: 10px 20px;
    color: white;
    background: var(--blue);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    touch-action: manipulation;
}
.btn:hover { filter: brightness(0.92); }
.btn:disabled { background: #ccc; cursor: not-allowed; filter: none; }
.btn.large { padding: 12px 24px; font-size: 16px; }
.btn.red { background: var(--red); }
.btn.red:disabled { background: #ccc; }
.btn.small { padding: 6px 12px; font-size: 13px; }
/* 補助的な操作（コピー、名前変更、戻るなど） */
.btn.sub { background: white; color: #333; box-shadow: inset 0 0 0 1px #aaa; }
.btn.sub:hover { background: #f0f0f0; filter: none; }
.btn.sub:disabled { background: #eee; color: #aaa; box-shadow: inset 0 0 0 1px #ddd; }
a.btn { display: inline-block; text-decoration: none; }
[hidden] { display: none !important; }

.choice {
    padding: 6px 12px;
    border: 1px solid var(--blue);
    background: white;
    color: var(--blue);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}
.choice:hover { background: #e3f2fd; }
.choice.active, .choice.active:hover { background: var(--blue); color: white; cursor: default; }
/* 変更できないときは、今の選択が分かるよう色を残したまま薄くします。 */
.choice:disabled { opacity: 0.45; cursor: not-allowed; }
.choice:disabled:not(.active):hover { background: white; }

/* 選択肢をひとつながりに並べた切り替え */
.seg { display: inline-flex; flex-wrap: wrap; }
.seg .choice { border-radius: 0; margin-left: -1px; }
.seg .choice:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.seg .choice:last-child { border-radius: 0 4px 4px 0; }

/* 抽選ごとの設定（確定・公開・URL・削除） */
.settings { text-align: left; }
.setting-row { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; padding: 10px 0; }
.setting-row + .setting-row { border-top: 1px solid #eee; }
.setting-label { width: 4.5em; color: #666; font-size: 14px; font-weight: bold; }
/* 各行の右の説明。操作の直後だけ、結果のメッセージに差し替わります。 */
.setting-note { color: #666; font-size: 14px; }
.setting-note.success { color: #2e7d32; font-weight: bold; }
.setting-note.error { color: #c62828; font-weight: bold; }

/* ---- ダイアログ ---- */
.dialog { margin: auto; border: none; border-radius: 8px; padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 8px 30px rgba(0,0,0,0.3); text-align: left; color: #333; }
.dialog::backdrop { background: rgba(0,0,0,0.45); }
.dialog h2 { font-size: 18px; margin-bottom: 10px; }
.dialog-message { font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
.dialog .input { width: 100%; margin-bottom: 12px; }
.dialog-error { color: #c62828; font-size: 13px; margin-bottom: 12px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 10px; }

.input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
}
.input:focus { border-color: var(--blue); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
    background: #eee;
    color: #666;
    white-space: nowrap;
}
.badge.blue { background: #e3f2fd; color: #1976D2; }
.badge.green { background: #e8f5e9; color: #2e7d32; }
.badge.orange { background: #fff3e0; color: #e65100; }

/* ---- メッセージ ---- */
.status-wrapper { min-width: 250px; height: 40px; display: flex; align-items: center; justify-content: center; }
.status { padding: 10px 20px; border-radius: 4px; display: none; font-size: 14px; white-space: nowrap; animation: fadeIn 0.3s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.status.success { display: block; background: #e8f5e9; color: var(--green); border: 1px solid var(--green); }
.status.info { display: block; background: #e3f2fd; color: var(--blue); border: 1px solid var(--blue); }
.status.error { display: block; background: #ffebee; color: var(--red); border: 1px solid var(--red); }
.error-message { padding: 20px; background: #ffebee; color: #c62828; border: 1px solid var(--red); border-radius: 4px; margin: 20px auto; max-width: 600px; }

/* ---- 一覧の表 ---- */
.list-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.list-table th { background: var(--blue); color: white; padding: 8px; white-space: nowrap; }
.list-table td { border: 1px solid #ddd; padding: 8px; text-align: center; }
.list-table td.left { text-align: left; }
.list-table tr:nth-child(even) { background: #f9f9f9; }
.list-table .actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.narrow { max-width: 900px; margin-left: auto; margin-right: auto; }

/* ---- 抽選の表 ---- */
.table-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin-bottom: 15px;
    -webkit-overflow-scrolling: touch;
}
.board { border-collapse: collapse; position: relative; user-select: none; table-layout: fixed; }
.board td {
    border: 1px solid #ddd;
    padding: 0;
    width: var(--cell-width);
    height: var(--cell-height);
    position: relative;
    background: white;
    cursor: pointer;
    overflow: hidden;
}
.cell-content {
    position: relative;
    width: var(--cell-width);
    height: var(--cell-height);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.main-icon {
    position: absolute;
    top: calc((var(--cell-width) - var(--icon-size)) / 2);
    left: calc((var(--cell-width) - var(--icon-size)) / 2);
    width: var(--icon-size);
    height: var(--icon-size);
    background-image: var(--icon-url);
    background-size: var(--sheet-width) auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    z-index: 1;
}
.style-icon {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--badge-width);
    height: var(--badge-height);
    background-image: var(--badge-url);
    background-size: var(--badge-width) auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    z-index: 2;
}
.board td.empty { background: #f9f9f9; cursor: default; }
.board td.empty .cell-content { color: #ccc; font-size: 20px; }
.board td.hover-target { background: #e3f2fd; }
.board td.search-highlight, .board td.search-highlight .cell-content { background: #ffeb3b; font-weight: bold; }

.board.text-mode td, .board.text-mode .cell-content { width: var(--text-cell-width); }
.board.text-mode .cell-content { font-size: 10px; padding: 2px 3px; line-height: 1.2; white-space: nowrap; }
.board.text-mode td.hover-target { font-weight: bold; }

.hover-frame {
    position: absolute;
    pointer-events: none;
    border: 3px solid var(--blue);
    background: rgba(33, 150, 243, 0.1);
    border-radius: 4px;
    z-index: 100;
    display: none;
}

/* ---- 拡大プレビュー ---- */
.hover-preview {
    position: fixed;
    pointer-events: none;
    z-index: 200;
    display: none;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    border: 2px solid var(--blue);
}
.hover-preview.touch-mode { pointer-events: auto; cursor: pointer; }
.preview-close-hint { display: none; text-align: center; padding: 6px 10px; background: rgba(0,0,0,0.7); color: white; font-size: 11px; border-radius: 0 0 6px 6px; }
.hover-preview.touch-mode .preview-close-hint { display: block; }
.hover-preview-grid { display: grid; gap: 2px; background: #333; padding: 2px; border-radius: 4px; }
.hover-preview-cell {
    width: 102px;
    height: 104px;
    background: white;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    border: 1px solid #666;
}
.hover-preview-cell.empty { background: #f0f0f0; color: #999; font-size: 24px; justify-content: center; }
.hover-preview-icon {
    position: relative;
    top: -8px;
    width: calc(var(--icon-size) * 2);
    height: calc(var(--icon-size) * 2);
    background-image: var(--icon-url);
    background-size: calc(var(--sheet-width) * 2) auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.hover-preview-style {
    position: absolute;
    top: 10px;
    left: 5px;
    width: calc(var(--badge-width) * 2);
    height: calc(var(--badge-height) * 2);
    background-image: var(--badge-url);
    background-size: calc(var(--badge-width) * 2) auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.hover-preview-label { background: rgba(0,0,0,0.8); color: white; font-size: 11px; padding: 3px 2px; text-align: center; border-radius: 2px; width: 100%; max-width: 100px; }

/* ---- シャッフルの演出 ---- */
@keyframes dropIn {
    0% { transform: translateY(-500px) scale(0.5); opacity: 0; }
    50% { opacity: 1; }
    70% { transform: translateY(10px) scale(1.1); }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}
.cell-content.dropping { animation: dropIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
@keyframes flipIn {
    0% { transform: perspective(400px) rotateY(90deg); opacity: 0; }
    40% { transform: perspective(400px) rotateY(-20deg); }
    60% { transform: perspective(400px) rotateY(10deg); opacity: 1; }
    80% { transform: perspective(400px) rotateY(-5deg); }
    100% { transform: perspective(400px) rotateY(0); opacity: 1; }
}
.cell-content.flipping { animation: flipIn 0.6s ease-in-out; }
@keyframes ripple {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
.cell-content.rippling { animation: ripple 0.5s ease-out; }

/* ---- 表示切り替えスイッチ ---- */
.view-toggle { display: flex; align-items: center; gap: 8px; }
.toggle-option { color: #ccc; font-size: 13px; user-select: none; }
.toggle-option.active { color: var(--blue); font-weight: bold; }
.toggle-switch { position: relative; width: 50px; height: 24px; background: #e0e0e0; border: none; border-radius: 20px; cursor: pointer; transition: background-color 0.3s; }
.toggle-switch.on { background: var(--blue); }
.toggle-slider { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: transform 0.3s; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.toggle-switch.on .toggle-slider { transform: translateX(26px); }

/* ---- 閲覧画面の詳細表 ---- */
.main-content { display: flex; justify-content: center; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.side-panel { min-width: 300px; max-width: 450px; text-align: left; overflow-x: auto; }
.detail-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.detail-table th { background: var(--blue); color: white; padding: 8px 6px; white-space: nowrap; }
.detail-table td { border: 1px solid #ddd; padding: 6px; text-align: center; white-space: nowrap; }
.detail-table tr:nth-child(even) { background: #f9f9f9; }
.detail-placeholder { color: #888; font-style: italic; padding: 20px; text-align: center; }

@media (max-width: 1200px) {
    .main-content { flex-direction: column; align-items: center; }
    .side-panel { width: 100%; max-width: 100%; min-width: 0; }
}
@media (max-width: 500px) {
    body { padding: 10px; }
    h1 { font-size: 20px; }
    .divider { border-left: none; padding-left: 0; }
    .detail-table { font-size: 11px; }
    .detail-table th, .detail-table td { padding: 5px 3px; }
    .status-wrapper { min-width: 0; }
}
