body {
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  background-color: #f0eee6;
  margin: 0;
  display: flex;
  justify-content: center;
  color: #4a4a4a;
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
  position: fixed;
  overscroll-behavior: none;
  touch-action: none;
}

.screen-container {
  width: 375px;
  height: 100dvh;
  max-height: 100dvh;
  background-color: #fff;
  position: relative;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  overscroll-behavior: none;
  touch-action: none;
}

.full-screen {
  height: 100dvh;
  justify-content: center;
  background-color: #fcfaf2;
}

.app-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 200px;
  letter-spacing: 2px;
}
.title-display--untitled {
  color: rgba(51, 51, 51, 0.55);
}

.tap-start {
  font-size: 14px;
  color: #888;
  animation: blink 2s infinite;
}

.tap-start a {
  text-decoration: none;
  color: inherit;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.btn-primary {
  background-color: #8c7b75;
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  text-decoration: none;
  margin-top: 20px;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
  background-color: #e8e4da;
  color: #5d5d5d;
  padding: 10px 18px;
  border-radius: 18px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.btn-secondary:hover {
  transform: translateY(-1px);
}

.btn-link {
  margin-top: 10px;
  color: #8c7b75;
  text-decoration: none;
  font-size: 14px;
}

.home-screen {
  padding: 32px 0 48px;
  text-align: center;
  background-image: url('../images/home.png');
  background-size: cover;
}

.greeting {
  font-size: 18px;
  margin-bottom: 10px;
}

.sub-text {
  font-size: 14px;
  color: #666;
  margin-bottom: 24px;
}

.status-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  background-color: #e8e4da;
  color: #5d5d5d;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
}

.menu-card {
  width: min(70vw, 270px);
  aspect-ratio: 1 / 1;
  margin: 18px 0;
  border-radius: 50%;
  overflow: hidden;
  display: block;
  text-decoration: none;
  transition: transform 0.2s ease;
}
.menu-card:hover {
  transform: translateY(-3px);
}
.menu-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-height: 740px) {
  .home-screen {
    padding: 24px 0 36px;
  }
  .menu-card {
    width: min(62vw, 235px);
    margin: 14px 0;
  }
}

@media (max-height: 660px) {
  .home-screen {
    padding: 20px 0 28px;
  }
  .menu-card {
    width: min(55vw, 210px);
    margin: 12px 0;
  }
}

@media (max-height: 600px) {
  .menu-card {
    width: min(50vw, 190px);
  }
}

.mode-screen {
  background-color: #444;
  justify-content: space-evenly;
  color: white;
  background-image: url('../images/mode-back.png');
  background-size: cover;
  padding: 40px 0;
}

.mode-circle {
  width: min(200px, 60vw);
  height: min(200px, 60vw);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: white;
  transition: transform 0.2s ease;
  background: none;
  overflow: hidden;
}

.mode-circle:hover {
  transform: scale(1.03);
}

.mode-slow,
.mode-quick {
  background: none;
}

.mode-title {
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  line-height: 1.3;
}

.mode-desc {
  font-size: 12px;
  margin-top: 10px;
}

.divider-or {
  font-size: 20px;
  color: #d4af37;
  font-weight: bold;
  margin: -10px 0;
  z-index: 10;
}

.select-screen {
  justify-content: center;
  background-color: #333;
  color: white;
  padding: 20px;
}

.select-screen.quick {
  background-image: url('../images/canvas-quick-back.png');
  background-size: cover;
}
.select-screen.slow {
  background-image: url('../images/canvas-slow-back.png');
  background-size: cover;
}

.prompt-text {
  font-size: 18px;
  text-align: center;
  margin-bottom: 30px;
}

.prompt-text span {
  font-size: 12px;
  opacity: 0.8;
}

.canvas-options {
  display: flex;
  gap: 20px;
}

.canvas-item {
  width: 150px;
  height: 150px;
  background-color: #fff;
  border: none;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.canvas-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

.canvas-item.circle {
  border-radius: 50%;
}

.canvas-item.square {
  border-radius: 8px;
}

.color-screen {
  background-color: #d8d0c0;
  padding-bottom: 30px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100dvh;
  overscroll-behavior: none;
  touch-action: pan-y;
}
.color-screen.quick {
  background-image: url('../images/draw-quick-back.png');
  background-size: cover;
}
.color-screen.slow {
  background-image: url('../images/draw-slow-back.png');
  background-size: cover;
}

.header-text {
  width: 100%;
  padding: 15px;
  background-color: #fff;
  text-align: center;
  font-weight: bold;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.color-cell {
  width: 100%;
  padding-bottom: 100%;
  position: relative;
  cursor: pointer;
  border-radius: 6px;
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-cell.selected {
  border-color: #8c7b75;
  transform: translateY(-2px);
}

.color-cell span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.55);
  font-size: 11px;
  font-weight: bold;
}

.selected-colors-info {
  width: 100%;
  padding: 10px 20px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, auto);
  gap: 8px;
  align-items: center;
  justify-items: center;
}

.selected-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 16px;
  background-color: rgba(0, 0, 0, 0.08);
  font-size: 12px;
  width: 100%;
  max-width: none;
  margin-bottom: 0;
  cursor: pointer;
  box-sizing: border-box;
  border: 2px solid transparent;
}

.selected-chip.selected {
  border-color: #8c7b75;
  background-color: rgba(0, 0, 0, 0.15);
}

.selected-hint {
  text-align: center;
  margin-bottom: 10px;
  font-size: 12px;
  color: #888;
}

.image-upload-section {
  margin: 10px 0;
  display: flex;
  justify-content: center;
}

.image-upload-btn {
  font-size: 14px;
  padding: 8px 16px;
}

.palette-form {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Responsive fixes for palette/color selection ===== */
/* Keep layout columnar and allow the central grid to scroll while
   keeping the action button ('決定して描く') visible above
   browser UI (tab bars) using safe-area insets. */
.color-screen {
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow children to shrink inside flex container */
  /* reserve space at the bottom for the action bar and mobile UI */
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 16px));
}

/* Make the color grid take remaining space and be scrollable */
.color-grid {
  flex: 1 1 auto;
  min-height: 0; /* required so flex child can scroll on iOS/Chrome */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.selected-colors-info,
.image-upload-section,
.header-text {
  flex-shrink: 0;
}

/* Stick the form (決定して描く) to the bottom of the scroll container
   so it's always reachable. Use safe-area fallback for older browsers. */
.palette-form {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 8px);
  padding: 10px 20px 6px;
  background: linear-gradient(transparent, rgba(255,255,255,0.95));
  z-index: 700;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
}

.palette-form .btn-primary {
  width: 100%;
  max-width: 360px;
}

/* Reduce grid density on narrow screens so vertical length is more reasonable */
@media (max-width: 420px), (max-height: 640px) {
  .color-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 16px;
  }
}

/* Further reduce grid columns and padding for very short screens to fit everything */
@media (max-height: 560px) {
  .color-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 12px;
  }
  .color-screen {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 16px));
  }
}

/* For extremely short screens, minimize further */
@media (max-height: 480px) {
  .color-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 8px;
  }
  .color-screen {
    padding-bottom: calc(50px + env(safe-area-inset-bottom, 16px));
  }
  .palette-form .btn-primary {
    padding: 8px 16px;
    font-size: 14px;
  }
}

/* Respect mobile browser chrome/tab bars for floating buttons */
.floating-color-btn {
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* Quick color bar and other sticky footers should also account for safe area */
.quick-color-bar,
.toolbar {
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.draw-screen {
  background-color: #a89f91;
  padding: 20px 0 30px;
}

.draw-screen-v2 {
  background-color: #a89f91;
  padding: 0;
  justify-content: flex-start;
  align-items: stretch;
  overflow: hidden;
  height: 100%;
  max-height: 100%;
  touch-action: none;
  position: relative;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
}

.draw-main {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 24px;
  box-sizing: border-box;
  gap: 0;
  overscroll-behavior: none;
  touch-action: pan-y;
}

.draw-screen-quick .draw-main {
  padding-bottom: 140px;
}

.draw-main::-webkit-scrollbar {
  display: none;
}

.draw-screen-slow {
  padding-bottom: 120px;
}

.draw-screen-quick {
  padding-bottom: 120px;
}
.draw-screen-v2.quick {
  background-image: url('../images/draw-quick-back.png');
  background-size: cover;
}
.draw-screen-v2.slow {
  background-image: url('../images/draw-slow-back.png');
  background-size: cover;
}

.draw-header {
  width: 100%;
  padding: 8px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}

.btn-undo {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 6px 12px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  transition: background-color 0.2s ease;
}

.btn-undo:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.canvas-wrapper {
  width: 300px;
  height: 300px;
  border-radius: 16px;
  overflow: hidden;
  background-color: #eaddcf;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
}

.canvas-wrapper.circle {
  border-radius: 50%;
}

.canvas-wrapper.square {
  border-radius: 16px;
}

#drawing-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.palette-bottom {
  position: absolute;
  bottom: 110px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-swatch.active {
  transform: translateY(-3px);
  border-color: #fff7d1;
}

.toolbar {
  position: absolute;
  bottom: 40px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.toolbar input[type="range"] {
  width: 120px;
}

.save-status {
  width: 100%;
  padding: 8px 20px;
  text-align: center;
  font-size: 11px;
  color: #fff;
  flex-shrink: 0;
}

.canvas-section {
  width: 100%;
  padding: 10px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.canvas-area {
  width: 280px;
  height: 280px;
  background-color: #eaddcf;
  position: relative;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.canvas-area.circle {
  border-radius: 50%;
}

.canvas-area.square {
  border-radius: 16px;
}

.placed-shape {
  position: absolute;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
  overflow: visible;
}

.placed-shape.selected {
  outline: 2px solid #fff7d1;
  outline-offset: 2px;
  transform: translateY(-2px);
}

.placed-shape.locked {
  cursor: default;
}

/* When a paint color is selected first, enable painting mode on the canvas to
   show a clickable cursor and hover affordance for shapes. */
.canvas-area.painting-mode .placed-shape {
  cursor: pointer;
}
.canvas-area.painting-mode .placed-shape:hover {
  transform: translateY(-2px) scale(1.02);
}

.placed-shape svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible; /* allow rotated parts to be visible outside the SVG viewport */
  transform-box: fill-box; /* useful if CSS transforms are used */
  transform-origin: center center;
}

.palette-section {
  width: 100%;
  padding: 10px 0;
  background-color: rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
  overflow: hidden;
}

.palette-header {
  font-size: 13px;
  color: #fff;
  margin-bottom: 8px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.palette-controls {
  display: flex;
  gap: 6px;
}

.btn-shuffle {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 4px 10px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 11px;
  transition: background-color 0.2s ease;
}

.btn-shuffle:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.btn-shuffle:disabled {
  background-color: rgba(255, 255, 255, 0.1);
  cursor: not-allowed;
  opacity: 0.5;
}

.shape-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 80px);
  gap: 8px;
  padding: 0 20px 10px 20px;
  max-width: 375px;
  margin: 0 auto;
}

.shape-swatch {
  width: 100%;
  height: 80px;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: transform 0.2s ease, background-color 0.2s ease;
  touch-action: none;
}

.shape-swatch:hover {
  transform: translateY(-2px);
  background-color: rgba(255, 255, 255, 0.25);
}

.shape-swatch:active {
  cursor: grabbing;
}

.shape-swatch.kept {
  outline: 3px solid #ff6b6b;
  outline-offset: -3px;
}

.shape-swatch.selected {
  outline: 3px solid #fff7d1;
  outline-offset: -3px;
}

.shape-preview {
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-preview svg {
  display: block;
}

.dragging-helper {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  transform: translate(-50%, -50%);
  opacity: 0.9;
}

.dragging-touch-block {
  touch-action: none;
  user-select: none;
}

.draw-controls {
  width: 100%;
  padding: 16px 20px 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
}

.draw-controls .btn-primary {
  min-width: 160px;
}

.quick-color-bar {
  width: 100%;
  padding: 12px 20px 18px;
  display: none;
  justify-content: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  position: sticky;
  bottom: 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
  z-index: 600;
  align-self: stretch;
}

.quick-color-bar.visible {
  display: flex;
}

.quick-color-swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid transparent;
  background-color: #d0ccc4;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.quick-color-swatch:hover,
.quick-color-swatch:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.16);
}

.quick-color-swatch:focus-visible {
  outline: 2px solid #fff7d1;
  outline-offset: 2px;
}

.quick-color-swatch.active {
  border-color: #4a4a4a;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.18);
  transform: translateY(-2px);
}

.floating-color-btn {
  position: fixed;
  bottom: 16px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: #8c7b75;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 900;
}

.floating-color-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.floating-color-btn:focus-visible {
  outline: 3px solid #fff7d1;
  outline-offset: 3px;
}

.color-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.color-modal.is-open {
  display: flex;
}

.color-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.color-modal__panel {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
  width: min(320px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 1;
}

.color-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: #4a4a4a;
}

.color-modal__close {
  background: none;
  border: none;
  color: #4a4a4a;
  font-size: 14px;
  cursor: pointer;
}

.color-modal__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 12px;
}

.color-modal__swatch {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-modal__swatch:hover,
.color-modal__swatch:focus-visible {
  transform: translateY(-2px);
  border-color: #8c7b75;
  outline: none;
}

.color-modal__swatch.active {
  border-color: #d4af37;
  transform: translateY(-3px);
}

@media (max-width: 540px) {
  .floating-color-btn {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
    font-size: 22px;
  }

  .color-modal__panel {
    width: min(360px, 92vw);
    padding: 16px;
  }
}

.size-control {
  position: fixed;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 20px;
  font-size: 12px;
  z-index: 999999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.size-control input[type="range"] {
  width: 120px;
}

.rotation-control,
.size-control-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

.value-display {
  width: 35px;
  text-align: right;
  display: inline-block;
}

@media (max-width: 540px) {
  .size-control {
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    position: fixed;
  }
}

.complete-screen {
  padding: 16px 20px 20px;
  text-align: center;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.complete-screen.quick {
  background-image: url('../images/complete-quick-back.png');
  background-size: cover;
}
.complete-screen.slow {
  background-image: url('../images/complete-slow-back.png');
  background-size: cover;
}

.complete-screen h2 {
  margin-bottom: 5px;
  margin-top: 0;
}

.complete-art {
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.complete-art img {
  width: 280px;
  height: 280px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

.art-meta {
  font-size: 12px;
  color: #777;
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
  padding-bottom: 8px;
}

.gallery-container {
  width: 375px;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

.gallery-screen {
  padding: 12px 0 15px;
  align-items: center;
  overflow-y: hidden;
  max-height: 100dvh;
  background-image: url('../images/gallery-back.png');
  background-size: cover;
  gap: 8px;
  position: absolute;
  top: 0;
  left: 0;
  width: 375px;
  transition: transform 0.3s ease-out;
}

.gallery-screen h2 {
  margin: 0;
  flex-shrink: 0;
  font-size: 18px;
  text-align: center;
}

.gallery-grid {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 16px;
  padding: 0 20px 8px 20px;
  flex: 1;
  min-height: 0;
  max-height: calc(100dvh - 140px);
  width: 100%;
  /* responsive sizes:
     --gallery-footer-height: explicit height reserved for the card footer (title/date)
     --gallery-card-size: target image square size (prefer 140px, but shrink if viewport too short)
     calculation: per-row available + footer height so the image area is allowed to reach 140px
  */
    --gallery-footer-height: 32px;
    /* total vertical gaps between stacked items in a column: 3 gaps of 12px when 4 items */
    --gallery-column-gaps: 36px; /* 3 * 12px */
    /* Compute per-item available height = (available grid height - gaps) / 4
      Then subtract footer height to get image square size. */
    --gallery-card-size: min(140px, calc((100dvh - 140px - var(--gallery-column-gaps)) / 4 - var(--gallery-footer-height)) );
}

.gallery-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
  height: 100%;
}

.gallery-card {
  background-color: #f7f4ec;
  border-radius: 12px;
  overflow: visible;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  width: var(--gallery-card-size, 140px);
  /* card height is image height + footer; keep auto so footer is outside the square image */
  height: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  position: relative;
}

.gallery-card.shape-circle {
  /* keep the card rectangular so footer stays readable; round only the image */
  border-radius: 12px;
  background-color: transparent;
  box-shadow: none;
}

.gallery-card.shape-circle img {
  width: 100%;
  height: var(--gallery-card-size, 140px);
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  display: block;
}

.gallery-card img {
  width: 100%;
  height: var(--gallery-card-size, 140px);
  object-fit: cover;
  min-height: 0;
  display: block;
}

.card-footer {
  /* footer is fixed height and excluded from image square area */
  height: var(--gallery-footer-height, 32px);
  line-height: var(--gallery-footer-height, 32px);
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 6px;
  margin-top: 4px;
}

.gallery-actions {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  padding: 0;
  flex-shrink: 0;
  width: 100%;
}

.gallery-actions .btn-secondary {
  max-width: 200px;
  justify-content: center;
}

.gallery-actions .btn-link {
  margin-top: 4px;
}

.empty-message {
  margin: 60px 0;
  text-align: center;
  color: #777;
}

@media (max-width: 420px) {
  body {
    align-items: flex-start;
    overflow: hidden;
  }
  .screen-container {
    width: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .gallery-container {
    width: 100%;
  }
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: #fff;
  padding: 20px;
  border-radius: 12px;
  max-width: 90%;
  max-height: 90%;
  position: relative;
  text-align: center;
}

.modal-content img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
}

/* Modal shape-specific styles */
.modal-content img.shape-circle {
  width: min(80vw, 360px);
  height: min(80vw, 360px);
  object-fit: cover;
  border-radius: 50%;
  display: block;
  margin: 0 auto;
}

.modal-content img.shape-square {
  width: min(80vw, 360px);
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  display: block;
  margin: 0 auto;
}

.modal-info {
  margin-top: 10px;
}

.modal-info h3 {
  margin: 0 0 5px 0;
}

.modal-info p {
  margin: 0 0 10px 0;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.modal-buttons .btn-primary {
  margin-top: 0;
}

.close {
  position: absolute;
  top: 10px;
  right: 15px;
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover {
  color: black;
}

/* ========== Hamburger Menu ========== */
.hamburger-button {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  background: rgba(59, 48, 107, 0.9);
  border: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
  transition: transform 0.3s ease, background 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.hamburger-button:hover {
  transform: scale(1.05);
  background: rgba(72, 61, 139, 0.95);
}

/* Disabled state for hamburger on draw screen */
.hamburger-button[disabled] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
  transform: none;
}

.hamburger-button span {
  display: block;
  width: 24px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.hamburger-button.active span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.hamburger-button.active span:nth-child(2) {
  opacity: 0;
}

.hamburger-button.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* メニュー全体の背景と配置 */
.menu-overlay {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  height: 100vh;
  background: linear-gradient(to bottom, #3b306b, #483d8b);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1500;
  transition: right 0.4s ease;
}

.menu-overlay.active {
  right: 0;
}

.menu-nav {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

/* リンクテキストのスタイル */
.menu-link {
  color: white;
  text-decoration: none;
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 5px;
  font-family: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.2s ease;
}

.menu-link:hover {
  transform: scale(1.05);
}

/* 装飾ラインと星のラッパー */
.menu-decoration {
  position: relative;
  width: 200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

/* ラインの共通スタイル */
.menu-decoration .line {
  flex-grow: 1;
  height: 2px;
  background: white;
  border-radius: 2px;
  opacity: 0.8;
}

/* 星の共通スタイル */
.menu-decoration .star {
  font-size: 14px;
  margin-left: 5px;
  line-height: 1;
}

/* --- 各色の定義 (グラデーションと発光効果) --- */

/* ホームへ (オレンジ) */
.item-orange .line {
  background: linear-gradient(90deg, transparent, #ffcc00);
  box-shadow: 0 0 8px #ffcc00;
}
.item-orange .star {
  color: #ffcc00;
  text-shadow: 0 0 8px #ffcc00;
}

/* アトリエ (青) */
.item-blue .line {
  background: linear-gradient(90deg, transparent, #00bfff);
  box-shadow: 0 0 8px #00bfff;
}
.item-blue .star {
  color: #00bfff;
  text-shadow: 0 0 8px #00bfff;
}

/* 展示室 (ピンク) */
.item-pink .line {
  background: linear-gradient(90deg, transparent, #ff69b4);
  box-shadow: 0 0 8px #ff69b4;
}
.item-pink .star {
  color: #ff69b4;
  text-shadow: 0 0 8px #ff69b4;
}

/* ログアウト (緑) */
.item-green .line {
  background: linear-gradient(90deg, transparent, #00ff7f);
  box-shadow: 0 0 8px #00ff7f;
}
.item-green .star {
  color: #00ff7f;
  text-shadow: 0 0 8px #00ff7f;
}

/* Chromaticity gallery styles */
.chromaticity-card {
  width: 100%;
  padding: 12px 16px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.plot-wrapper {
  width: 100%;
  max-width: 640px;
  background: transparent;
  border-radius: 10px;
  box-shadow: none;
  padding: 8px;
}
#chromaticityCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: transparent;
}
.chromaticity-card .controls { width: 100%; display:flex; justify-content:space-between; align-items:center; gap:8px; }
.chromaticity-card .controls .hint { font-size: 13px; color: #666; margin:0; }
.chromaticity-card .actions { display:flex; gap:6px; align-items:center; }
#zoomLevelChrom { font-weight:600; color:#444; }


/* ========== Draw Screen Responsive Design ========== */
/* Continuous responsive scaling for various screen heights */

/* Base: Full size for tall screens (>800px height) */
/* Canvas: 280x280, Palette cells: 80px */

/* Medium height screens (700-800px) */
@media (max-height: 800px) {
  .canvas-area {
    width: 260px;
    height: 260px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 75px);
  }
  
  .shape-swatch {
    height: 75px;
  }
  
  .draw-main {
    padding: 0 0 20px;
  }
}

/* Shorter screens (600-700px) */
@media (max-height: 700px) {
  .canvas-area {
    width: 240px;
    height: 240px;
  }
  
  .canvas-section {
    padding: 8px 20px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 70px);
    gap: 6px;
  }
  
  .shape-swatch {
    height: 70px;
  }
  
  .palette-section {
    padding: 8px 0;
  }
  
  .draw-controls {
    padding: 12px 20px 0;
  }
  
  .draw-main {
    padding: 0 0 16px;
  }
}

/* Small height screens (500-600px) */
@media (max-height: 600px) {
  .canvas-area {
    width: 220px;
    height: 220px;
  }
  
  .canvas-section {
    padding: 6px 20px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 65px);
    gap: 5px;
    padding: 0 20px 8px 20px;
  }
  
  .shape-swatch {
    height: 65px;
  }
  
  .palette-section {
    padding: 6px 0;
  }
  
  .palette-header {
    font-size: 12px;
    margin-bottom: 6px;
  }
  
  .draw-controls {
    padding: 10px 20px 0;
  }
  
  .draw-controls .btn-primary {
    min-width: 140px;
    padding: 10px 20px;
    font-size: 14px;
  }
  
  .draw-header {
    padding: 6px 20px;
    font-size: 12px;
  }
  
  .btn-undo {
    padding: 5px 10px;
    font-size: 11px;
  }
  
  .draw-screen-quick .draw-main {
    padding-bottom: 120px;
  }
  
  .draw-screen-slow {
    padding-bottom: 100px;
  }
}

/* Very small height screens (420-500px) */
@media (max-height: 500px) {
  .canvas-area {
    width: 200px;
    height: 200px;
  }
  
  .canvas-section {
    padding: 5px 15px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 60px);
    gap: 4px;
    padding: 0 15px 6px 15px;
  }
  
  .shape-swatch {
    height: 60px;
  }
  
  .palette-section {
    padding: 5px 0;
  }
  
  .palette-header {
    font-size: 11px;
    margin-bottom: 5px;
    padding: 0 15px;
  }
  
  .draw-controls {
    padding: 8px 15px 0;
  }
  
  .draw-controls .btn-primary {
    min-width: 120px;
    padding: 8px 16px;
    font-size: 13px;
  }
  
  .draw-header {
    padding: 5px 15px;
    font-size: 11px;
  }
  
  .btn-undo {
    padding: 4px 8px;
    font-size: 10px;
  }
  
  .btn-shuffle {
    padding: 3px 8px;
    font-size: 10px;
  }
  
  .draw-main {
    padding: 0 0 12px;
  }
  
  .draw-screen-quick .draw-main {
    padding-bottom: 110px;
  }
  
  .quick-color-bar {
    padding: 10px 15px 14px;
    gap: 12px;
  }
  
  .quick-color-swatch {
    width: 44px;
    height: 44px;
  }
  
  .draw-screen-slow {
    padding-bottom: 90px;
  }
  
  .floating-color-btn {
    width: 50px;
    height: 50px;
    font-size: 22px;
    bottom: 12px;
    right: 20px;
  }
}

/* Extra small height screens (350-420px) */
@media (max-height: 420px) {
  .canvas-area {
    width: 180px;
    height: 180px;
  }
  
  .canvas-section {
    padding: 4px 12px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 55px);
    gap: 3px;
    padding: 0 12px 5px 12px;
  }
  
  .shape-swatch {
    height: 55px;
    border-radius: 10px;
  }
  
  .palette-section {
    padding: 4px 0;
  }
  
  .palette-header {
    font-size: 10px;
    margin-bottom: 4px;
    padding: 0 12px;
  }
  
  .palette-controls {
    gap: 4px;
  }
  
  .draw-controls {
    padding: 6px 12px 0;
  }
  
  .draw-controls .btn-primary {
    min-width: 100px;
    padding: 7px 14px;
    font-size: 12px;
  }
  
  .draw-header {
    padding: 4px 12px;
    font-size: 10px;
  }
  
  .btn-undo {
    padding: 3px 7px;
    font-size: 9px;
  }
  
  .btn-shuffle {
    padding: 2px 6px;
    font-size: 9px;
  }
  
  .draw-main {
    padding: 0 0 10px;
  }
  
  .save-status {
    padding: 4px 12px;
    font-size: 9px;
  }
  
  .draw-screen-quick .draw-main {
    padding-bottom: 100px;
  }
  
  .quick-color-bar {
    padding: 8px 12px 12px;
    gap: 10px;
  }
  
  .quick-color-swatch {
    width: 40px;
    height: 40px;
    border-width: 2px;
  }
  
  .draw-screen-slow {
    padding-bottom: 80px;
  }
  
  .floating-color-btn {
    width: 46px;
    height: 46px;
    font-size: 20px;
    bottom: 10px;
    right: 16px;
  }
}

/* Tiny height screens (<350px) - Extreme minimal mode */
@media (max-height: 350px) {
  .canvas-area {
    width: 160px;
    height: 160px;
  }
  
  .canvas-section {
    padding: 3px 10px;
  }
  
  .shape-palette {
    grid-template-rows: repeat(2, 50px);
    gap: 2px;
    padding: 0 10px 4px 10px;
  }
  
  .shape-swatch {
    height: 50px;
    border-radius: 8px;
  }
  
  .palette-section {
    padding: 3px 0;
  }
  
  .palette-header {
    font-size: 9px;
    margin-bottom: 3px;
    padding: 0 10px;
  }
  
  .draw-controls {
    padding: 5px 10px 0;
  }
  
  .draw-controls .btn-primary {
    min-width: 90px;
    padding: 6px 12px;
    font-size: 11px;
  }
  
  .draw-header {
    padding: 3px 10px;
    font-size: 9px;
  }
  
  .btn-undo {
    padding: 2px 6px;
    font-size: 8px;
  }
  
  .btn-shuffle {
    padding: 2px 5px;
    font-size: 8px;
  }
  
  .draw-main {
    padding: 0 0 8px;
  }
  
  .save-status {
    padding: 3px 10px;
    font-size: 8px;
  }
  
  .draw-screen-quick .draw-main {
    padding-bottom: 90px;
  }
  
  .quick-color-bar {
    padding: 6px 10px 10px;
    gap: 8px;
  }
  
  .quick-color-swatch {
    width: 36px;
    height: 36px;
  }
  
  .draw-screen-slow {
    padding-bottom: 70px;
  }
  
  .floating-color-btn {
    width: 42px;
    height: 42px;
    font-size: 18px;
    bottom: 8px;
    right: 12px;
  }
}
