* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #f38020;
  --accent-dark: #d96c0e;
  --border: #e2e6ea;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 24px 16px;
  text-align: center;
}

.site-header h1 {
  font-size: 1.6rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  display: flex;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  gap: 24px;
  align-items: flex-start;
}

main {
  flex: 1;
  min-width: 0;
}

/* ---- サイドバー ---- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 12px;
  position: sticky;
  top: 16px;
}

.sidebar-title {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.category-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.category-item:hover {
  background: #f2f4f6;
}

.category-item.active {
  background: var(--accent);
  color: #fff;
}

.category-item .count {
  font-size: 0.78rem;
  color: var(--muted);
  background: #eef0f3;
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 26px;
  text-align: center;
}

.category-item.active .count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
  }

  .category-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .category-item {
    width: auto;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.88rem;
  }
}

/* ---- 管理者ログイン ---- */

.admin-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 20px;
  margin-bottom: 32px;
}

.admin-panel form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-panel label {
  font-size: 0.85rem;
  color: var(--muted);
}

.admin-panel input[type="password"] {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  width: 200px;
}

.admin-panel input[type="password"]:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.admin-panel button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.9rem;
  cursor: pointer;
}

.admin-panel button:hover {
  background: var(--accent-dark);
}

#admin-status {
  font-size: 0.85rem;
  color: #d0342c;
}

.upload-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.upload-panel-header h2 {
  margin-bottom: 0;
}

.logout-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.logout-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ---- アップロードフォーム ---- */

.upload-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 32px;
}

.upload-panel h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.field input[type="text"],
.field select {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
}

.field input[type="text"]:focus,
.field select:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

#upload-status {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.4em;
}

#upload-status.error {
  color: #d0342c;
}

#upload-status.success {
  color: #1a7f37;
}

/* ---- ギャラリー見出し ---- */

.gallery-panel {
  position: relative;
}

.gallery-title {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.admin-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ---- ドラッグ&ドロップ ---- */

.drop-overlay {
  display: none;
  position: fixed;
  inset: 12px;
  border: 4px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(243, 128, 32, 0.12);
  color: var(--accent-dark);
  font-size: 1.4rem;
  font-weight: bold;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  z-index: 200;
}

.drop-overlay.visible {
  display: flex;
}

.drop-overlay.warning {
  border-color: #d0342c;
  background: rgba(208, 52, 44, 0.1);
  color: #d0342c;
}

.upload-dest {
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.upload-dest strong {
  color: var(--accent-dark);
  background: #fdeedd;
  border-radius: 999px;
  padding: 2px 12px;
}

.upload-dest strong.unselected {
  color: #d0342c;
  background: #fbe4e2;
}

.upload-dest-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.card.dragging {
  opacity: 0.4;
}

.card.drag-target {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

body.is-admin .card {
  cursor: grab;
}

/* ---- ギャラリー ---- */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.card .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  cursor: pointer;
  background: #eceef1;
  border: none;
  padding: 0;
}

.card .info {
  padding: 8px 10px;
}

.card .name-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.card .name {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.card .rename-button {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .rename-button,
.card:focus-within .rename-button {
  opacity: 1;
}

.card .rename-button:hover {
  color: var(--accent-dark);
}

.card .rename-input {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
}

.card .edit-button {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .edit-button,
.card:focus-within .edit-button {
  opacity: 1;
}

.card .edit-button:hover {
  background: var(--accent);
}

.card .category-label {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--accent-dark);
  background: #fdeedd;
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 4px;
}

.card .delete-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .delete-button,
.card:focus-within .delete-button {
  opacity: 1;
}

.card .delete-button:hover {
  background: #d0342c;
}

.empty-message {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
}

/* ---- ペイントエディタ ---- */

.editor {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  z-index: 150;
}

.editor[hidden] {
  display: none;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  background: #1c1f24;
}

.editor-colors {
  display: flex;
  gap: 6px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  padding: 0;
}

.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.editor-size {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #d5d8dd;
  font-size: 0.85rem;
}

.editor-tool {
  background: #33383f;
  color: #e7e9ec;
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

.editor-tool:hover {
  background: #454b54;
}

.editor-tool.active {
  background: var(--accent);
  color: #fff;
}

.editor-spacer {
  flex: 1;
}

.editor-save {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 20px;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
}

.editor-save:hover {
  background: var(--accent-dark);
}

.editor-save:disabled {
  background: #6b7280;
  cursor: not-allowed;
}

.editor-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
}

.editor-stack {
  position: relative;
  max-width: 100%;
  max-height: 100%;
}

.editor-stack canvas {
  display: block;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 110px);
}

#base-canvas {
  border-radius: 6px;
}

#draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ---- ライトボックス ---- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.lightbox[hidden] {
  display: none;
}

.lightbox figure {
  max-width: 92vw;
  max-height: 90vh;
  text-align: center;
}

.lightbox img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 8px;
}

.lightbox figcaption {
  color: #e5e7eb;
  font-size: 0.9rem;
  margin-top: 10px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2.2rem;
  cursor: pointer;
  line-height: 1;
}
