:root {
  --wood-dark: #4e2f16;
  --wood-mid: #734723;
  --wood-light: #8d5a31;
  --cork-base: #c8945a;
  --cork-dark: #b37b42;
  --paper-bg: #fffdf8;
  --text-main: #2b2118;
  --text-muted: #6f5b47;
  --accent: #b83227;
  --accent-hover: #99251c;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
  color: var(--text-main);
  background-color: var(--wood-dark);
}

.hidden {
  display: none !important;
}

/* Header */
.board-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--wood-light) 0%, var(--wood-mid) 60%, var(--wood-dark) 100%);
  border-bottom: 2px solid #3b220e;
  color: #fff8ee;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.board-badge {
  font-size: 1.25rem;
}

.board-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.view-toggle {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.toggle-btn {
  border: none;
  background: transparent;
  color: #efe2d1;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn.active {
  background: #fff7ea;
  color: var(--wood-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-wood {
  background: rgba(255, 248, 238, 0.15);
  color: #fff8ee;
  border: 1px solid rgba(255, 248, 238, 0.35);
}
.btn-wood:hover {
  background: rgba(255, 248, 238, 0.26);
}

.btn-secondary {
  background: #e6ddd2;
  color: #3a2d20;
}
.btn-secondary:hover {
  background: #d7cbbd;
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.8rem;
  background: #fff;
  color: var(--wood-dark);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Admin Banner */
.admin-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: #fef3c7;
  color: #78350f;
  border-bottom: 1px solid #f59e0b;
  font-size: 0.86rem;
}

/* Wood Frame & Realistic Corkboard */
.wood-frame {
  padding: 14px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.02) 0px,
      rgba(255, 255, 255, 0.02) 2px,
      rgba(0, 0, 0, 0.04) 2px,
      rgba(0, 0, 0, 0.04) 6px
    ),
    linear-gradient(135deg, var(--wood-light) 0%, var(--wood-mid) 50%, var(--wood-dark) 100%);
  min-height: calc(100vh - 58px);
}

.corkboard {
  position: relative;
  width: 100%;
  min-height: calc(100vh - 86px);
  border-radius: 6px;
  border: 3px solid #3e230d;
  box-shadow:
    inset 0 0 28px rgba(45, 24, 6, 0.55),
    inset 0 2px 6px rgba(0, 0, 0, 0.4),
    0 2px 10px rgba(0, 0, 0, 0.4);
  /* Realistic Cork Texture */
  background-color: var(--cork-base);
  background-image:
    radial-gradient(ellipse at center, rgba(255, 236, 204, 0.16) 0%, rgba(120, 74, 30, 0.22) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='cork'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0.35 0 0 0 0.68  0.22 0 0 0 0.44  0.10 0 0 0 0.24  0 0 0 0.48 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23cork)'/%3E%3C/svg%3E");
  overflow: auto;
  padding: 20px;
}

.corkboard.drag-over-board {
  outline: 4px dashed #fff8ee;
  outline-offset: -8px;
}

/* Free-form Board Mode */
.corkboard.mode-board {
  min-height: max(calc(100vh - 86px), 860px);
}

/* List / Grid Mode (Mobile-friendly & high readability) */
.corkboard.mode-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 24px;
  align-items: start;
  align-content: start;
}

.corkboard.mode-list .pin-card {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  width: 100% !important;
  transform: none !important;
}

/* Empty State */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: #3d240e;
  background: rgba(255, 245, 228, 0.42);
  border-radius: 6px;
  pointer-events: none;
}

.empty-state p {
  margin: 4px 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.empty-state .empty-sub {
  font-size: 0.9rem;
  font-weight: 500;
}

/* Pinned Paper Card */
.pin-card {
  position: absolute;
  background: var(--paper-bg);
  padding: 22px 10px 10px 10px;
  border-radius: 2px;
  box-shadow:
    0 10px 22px rgba(34, 18, 5, 0.34),
    0 3px 6px rgba(34, 18, 5, 0.22);
  transition: box-shadow 0.15s ease;
  user-select: none;
  touch-action: auto;
  z-index: 2;
}

.pin-card:hover {
  z-index: 10;
  box-shadow:
    0 14px 28px rgba(34, 18, 5, 0.42),
    0 4px 8px rgba(34, 18, 5, 0.25);
}

.admin-unlocked .corkboard.mode-board .pin-card {
  cursor: grab;
  touch-action: none;
}

.pin-card.is-dragging {
  cursor: grabbing !important;
  z-index: 30 !important;
  box-shadow:
    0 22px 38px rgba(34, 18, 5, 0.48),
    0 6px 12px rgba(34, 18, 5, 0.3);
}

/* 3D Pushpin (画鋲) */
.pushpin {
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow:
    0 3px 5px rgba(0, 0, 0, 0.45),
    inset -3px -3px 5px rgba(0, 0, 0, 0.35),
    inset 3px 3px 5px rgba(255, 255, 255, 0.65);
  z-index: 3;
  pointer-events: none;
}

.pushpin::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 6px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 50%;
  filter: blur(1px);
}

.pushpin.red    { background: radial-gradient(circle at 35% 30%, #ff7b72, #c92a2a); }
.pushpin.blue   { background: radial-gradient(circle at 35% 30%, #74c0fc, #1864ab); }
.pushpin.yellow { background: radial-gradient(circle at 35% 30%, #ffe066, #e67700); }
.pushpin.green  { background: radial-gradient(circle at 35% 30%, #8ce99a, #2b8a3e); }

.pin-img-wrap {
  display: block;
  width: 100%;
  overflow: hidden;
  border: 1px solid #e7dfd3;
  background: #f5f0e8;
  cursor: zoom-in;
}

.pin-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.pin-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 0 2px;
}

.pin-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-word;
}

.pin-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Admin Card Controls */
.pin-admin-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed #d8cbb8;
}

.admin-unlocked .pin-admin-bar {
  display: flex;
}

.pin-size-btns {
  display: flex;
  gap: 4px;
}

.btn-icon {
  border: 1px solid #cbbba7;
  background: #fff;
  color: #3a2d20;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-icon:hover {
  background: #f3ece2;
}

.btn-delete {
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 4px;
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-delete:hover {
  background: #fecaca;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 12, 5, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #fffdf9;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  border: 2px solid #d8c6b0;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-sm {
  max-width: 360px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}

.modal-desc {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.pin-input {
  width: 100%;
  font-size: 2rem;
  letter-spacing: 0.6rem;
  text-align: center;
  padding: 10px;
  border: 2px solid #cbb8a2;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
}
.pin-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cbb8a2;
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.help-text {
  margin: 5px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.preview-box {
  margin-bottom: 14px;
  border: 1px solid #e0d4c4;
  border-radius: 6px;
  padding: 6px;
  background: #f8f3eb;
  text-align: center;
}

.preview-box img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 4px;
}

.pin-colors {
  display: flex;
  gap: 10px;
  padding-top: 4px;
}

.color-dot {
  position: relative;
  cursor: pointer;
}

.color-dot input {
  position: absolute;
  opacity: 0;
}

.color-dot span {
  display: block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.color-dot.red span    { background: #d63031; }
.color-dot.blue span   { background: #0984e3; }
.color-dot.yellow span { background: #f39c12; }
.color-dot.green span  { background: #27ae60; }

.color-dot input:checked + span {
  border-color: #2b2118;
  transform: scale(1.15);
}

.error-text {
  color: #b91c1c;
  font-size: 0.86rem;
  font-weight: 700;
  margin: 6px 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 5, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.lightbox img {
  max-width: 96vw;
  max-height: 84vh;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  background: #fff;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #1f1710;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.lightbox-caption {
  color: #f8efe4;
  margin-top: 12px;
  font-size: 0.95rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2b2118;
  color: #fff8ee;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 300;
}

@media (max-width: 767px) {
  .wood-frame {
    padding: 8px;
  }
  .corkboard {
    padding: 14px;
  }
  .board-header h1 {
    font-size: 0.98rem;
  }
}
