:root {
  color-scheme: light;
  --ink: #23211f;
  --muted: #6d6760;
  --paper: #f7f3ea;
  --wall: #ebe4d6;
  --line: #d8cec0;
  --accent: #8f3f34;
  --accent-dark: #6f2d25;
  --focus: #166c78;
  --shadow: 0 18px 50px rgba(45, 34, 23, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #fcfaf5 0%, var(--paper) 100%);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.screen {
  display: none;
}

.screen-active {
  display: block;
}

#select-screen {
  padding-bottom: 168px;
}

#intro-screen {
  min-height: calc(100vh - 112px);
}

.screen-header {
  margin-bottom: 24px;
}

.screen-header.compact {
  margin-bottom: 18px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

.back-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin: 0 0 14px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 0.95rem;
  text-decoration: none;
}

.back-button::before {
  content: "<";
  margin-right: 6px;
}

.back-button:hover {
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4.8vw, 3.15rem);
  font-weight: 650;
  line-height: 1.18;
  letter-spacing: 0;
}

.lead {
  max-width: 46rem;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2.35vw, 1.22rem);
  line-height: 1.85;
}

.selected-theme-label {
  width: fit-content;
  max-width: 100%;
  margin: 16px 0 0;
  padding-bottom: 8px;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  font-size: clamp(1.28rem, 3.4vw, 2rem);
  font-weight: 600;
  line-height: 1.4;
}

.intro-header {
  max-width: 720px;
}

.intro-visual-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(100%, 720px);
  margin: 14px auto 18px;
}

.intro-title-image {
  display: block;
  width: min(58%, 420px);
  height: auto;
  margin: 0;
}

.intro-start-button {
  min-width: 220px;
}

.intro-bottom-visual {
  display: block;
  width: min(38%, 280px);
  height: auto;
  margin: 0;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.theme-card {
  min-height: 112px;
  padding: 18px;
  color: var(--ink);
  text-align: left;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(58, 45, 31, 0.08);
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 500;
  line-height: 1.45;
}

.theme-card:hover {
  border-color: var(--accent);
}

.theme-more-button {
  min-width: 220px;
}

.theme-more-button[hidden] {
  display: none;
}

.work-more-button {
  display: block;
  min-width: 220px;
  margin: 22px auto 0;
}

.work-more-button[hidden] {
  display: none;
}

.action-bar,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-summary,
.selection-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 0;
  color: var(--muted);
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.selected-tray {
  position: fixed;
  right: 50%;
  bottom: 12px;
  z-index: 20;
  width: min(430px, calc(100% - 32px));
  padding: 10px;
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(45, 34, 23, 0.18);
  transform: translateX(50%);
  backdrop-filter: blur(8px);
}

.selected-tray-ready {
  border-color: rgba(143, 63, 52, 0.55);
  box-shadow: 0 14px 42px rgba(143, 63, 52, 0.2);
}

.selected-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.selected-slot {
  position: relative;
  display: block;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: #eee8dc;
  border: 1px dashed #cfc4b4;
  border-radius: 8px;
  overflow: hidden;
  cursor: default;
}

.selected-slot-filled {
  background: #fffdf8;
  border-style: solid;
  border-color: var(--focus);
}

.selected-slot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selected-slot-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: #fff;
  background: rgba(35, 33, 31, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  font-size: 1rem;
  line-height: 1;
}

.selected-slot-remove:hover {
  background: rgba(35, 33, 31, 0.95);
}

.selected-tray-button {
  width: 100%;
  margin-top: 10px;
}

.title-idea {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.title-idea span {
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 700;
}

.title-idea strong {
  min-width: 0;
  color: var(--ink);
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.work-grid {
  column-count: 4;
  column-gap: 16px;
}

.work-grid-extra:not(:empty) {
  margin-top: 22px;
}

.work-card {
  appearance: none;
  display: block;
  width: 100%;
  margin: 0 0 16px;
  min-width: 0;
  padding: 12px;
  color: inherit;
  text-align: left;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(58, 45, 31, 0.08);
  break-inside: avoid;
  cursor: pointer;
}

.work-card[aria-pressed="true"] {
  border-color: var(--focus);
  outline: 3px solid rgba(22, 108, 120, 0.22);
}

.work-card:focus-visible {
  outline: 3px solid rgba(22, 108, 120, 0.28);
  outline-offset: 2px;
}

.art-thumb {
  display: block;
  position: relative;
  background: #ede8dc;
  overflow: hidden;
}

.art-thumb img {
  display: block;
  width: 100%;
  height: auto;
}

.zoom-button {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 7px;
  background: rgba(35, 33, 31, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
}

.zoom-button:hover {
  background: rgba(35, 33, 31, 0.88);
}

.zoom-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.work-meta {
  display: none;
}

.work-meta strong {
  overflow-wrap: anywhere;
}

.work-meta span {
  color: var(--muted);
  font-size: 0.9rem;
}

.primary-button,
.secondary-button,
.quiet-button,
.text-button,
.suggestion-chip {
  min-height: 44px;
  border-radius: 8px;
}

.primary-button {
  padding: 0 20px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  font-weight: 700;
}

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

.primary-button:disabled {
  cursor: not-allowed;
  background: #c8beb1;
  border-color: #c8beb1;
}

.secondary-button,
.quiet-button,
.text-button,
.suggestion-chip {
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
}

.secondary-button {
  padding: 0 18px;
}

.text-button {
  padding: 0 14px;
}

.quiet-button {
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-weight: 600;
}

.quiet-button:hover {
  color: var(--accent);
}

.action-bar {
  margin-top: 22px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.complete-actions {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin-top: 22px;
}

.app-footer {
  width: min(100% - 32px, 1120px);
  margin: 24px auto 32px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.share-actions {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(100%, 360px);
}

.share-actions .primary-button {
  width: 100%;
}

.share-sub-actions,
.replay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.share-sub-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
}

.share-sub-actions .secondary-button {
  width: 100%;
  padding-inline: 12px;
}

.replay-actions {
  gap: 6px;
}

.suggestion-chip {
  padding: 0 12px;
}

.share-preview-shell {
  display: grid;
  place-items: center;
}

.share-preview-canvas {
  display: block;
  width: min(100%, 540px);
  height: auto;
  background: var(--wall);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.image-modal[hidden] {
  display: none;
}

.complete-animation[hidden] {
  display: none;
}

.complete-animation {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 250, 241, 0.94);
}

.complete-animation img {
  display: block;
  max-width: min(78vw, 420px);
  max-height: 70vh;
  width: auto;
  height: auto;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(24, 22, 20, 0.68);
  border: 0;
}

.modal-content {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  max-width: min(920px, 92vw);
  max-height: 88vh;
  margin: 0;
  padding: 16px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.modal-content img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  justify-self: center;
  object-fit: contain;
}

.modal-content figcaption {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
}

@media (max-width: 860px) {
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .work-grid {
    column-count: 2;
  }

}

@media (max-width: 560px) {
  #intro-screen {
    min-height: calc(100vh - 64px);
  }

  .intro-visual-row {
    gap: 8px;
    margin: 10px auto 14px;
  }

  .intro-title-image {
    width: 58%;
  }

  .intro-bottom-visual {
    width: 38%;
  }

  .app-shell {
    width: min(100% - 20px, 1120px);
    padding: 18px 0;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .selection-summary,
  .selection-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .selection-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .title-idea {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .work-grid {
    column-gap: 10px;
  }

  .work-card {
    margin-bottom: 10px;
    padding: 8px;
  }

  .primary-button,
  .secondary-button,
  .text-button {
    width: 100%;
  }
}
