:root {
  color-scheme: light;
  --bg: #fff8ed;
  --ink: #263238;
  --muted: #63727a;
  --panel: #ffffff;
  --line: #e7d8c7;
  --accent: #ff7a59;
  --accent-deep: #dd4e2f;
  --green: #4caf70;
  --blue: #4b8ee8;
  --yellow: #ffd766;
  --shadow: 0 16px 36px rgba(59, 42, 24, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: linear-gradient(135deg, #fff8ed 0%, #f4fbff 46%, #effaf5 100%);
}

button {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(280px, 420px);
  gap: 24px;
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  align-items: center;
}

.stage,
.controls {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(231, 216, 199, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage {
  display: grid;
  justify-items: center;
  gap: 22px;
  padding: clamp(24px, 5vw, 48px);
}

.title-area {
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-deep);
  font-size: 0.95rem;
  font-weight: 700;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.7rem);
  line-height: 1.05;
}

.roulette-area {
  position: relative;
  display: grid;
  place-items: center;
  width: min(76vw, 390px);
  aspect-ratio: 1;
}

.pointer {
  position: absolute;
  top: -2px;
  z-index: 2;
  width: 0;
  height: 0;
  border-left: 22px solid transparent;
  border-right: 22px solid transparent;
  border-top: 34px solid var(--accent-deep);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.18));
}

.wheel {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 12px solid #fff;
  border-radius: 50%;
  background: conic-gradient(
    #ff8f70 0deg 45deg,
    #ffd766 45deg 90deg,
    #5acb84 90deg 135deg,
    #65a6ff 135deg 180deg,
    #f990c8 180deg 225deg,
    #9b83f6 225deg 270deg,
    #6fd5d5 270deg 315deg,
    #ffc069 315deg 360deg
  );
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.5), 0 18px 34px rgba(64, 42, 28, 0.18);
  transition: transform 2.2s cubic-bezier(0.12, 0.74, 0.24, 1);
}

.wheel-face {
  display: grid;
  place-items: center;
  width: 46%;
  height: 46%;
  border: 8px solid #fff3dc;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(38, 50, 56, 0.16);
}

.wheel-icon {
  font-size: clamp(3.8rem, 10vw, 6rem);
  line-height: 1;
}

.result-panel {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(100%, 520px);
  min-height: 300px;
  padding: 16px 18px;
  text-align: center;
  border: 2px solid #ffe0bd;
  border-radius: 8px;
  background: #fffdf8;
}

.result-image {
  width: min(100%, 270px);
  aspect-ratio: 16 / 13;
  object-fit: contain;
  border: 2px solid #fff0d3;
  border-radius: 8px;
  background: #ffffff;
}

.result-image.is-spinning {
  opacity: 0.42;
}

.result-category {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.result-text {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 1.1;
}

.actions {
  width: min(100%, 360px);
}

.spin-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 12px 20px;
  color: #ffffff;
  font-size: 1.35rem;
  font-weight: 800;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  box-shadow: 0 10px 0 #a83d25, 0 18px 28px rgba(221, 78, 47, 0.25);
  cursor: pointer;
}

.spin-button:active {
  transform: translateY(5px);
  box-shadow: 0 5px 0 #a83d25, 0 10px 18px rgba(221, 78, 47, 0.2);
}

.spin-button:disabled {
  opacity: 0.72;
  cursor: wait;
}

.history-panel {
  width: min(100%, 520px);
  padding: 14px;
  border: 2px solid #d8e6ef;
  border-radius: 8px;
  background: #f8fcff;
}

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

.history-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-button {
  min-height: 40px;
  padding: 8px 12px;
  color: var(--ink);
  font-weight: 800;
  border: 2px solid #cfe1ef;
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.history-button:hover,
.history-button:focus-visible {
  border-color: var(--blue);
  outline: none;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  max-height: 280px;
  overflow: auto;
}

.history-list.is-hidden {
  display: none;
}

.history-empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.history-item {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 154px;
  padding: 10px;
  border: 1px solid #e6dccd;
  border-radius: 8px;
  background: #fffdf8;
}

.history-item img {
  width: 96px;
  aspect-ratio: 16 / 13;
  object-fit: contain;
  border: 1px solid #fff0d3;
  border-radius: 8px;
  background: #ffffff;
}

.history-number {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #ffffff;
  font-weight: 900;
  border-radius: 50%;
  background: var(--accent-deep);
}

.history-item-name,
.history-item-category {
  display: block;
  text-align: center;
  line-height: 1.25;
}

.history-item-name {
  font-weight: 900;
}

.history-item-category {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.controls {
  padding: 22px;
}

.controls-header h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.selection-summary {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.category-button {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px;
  color: var(--ink);
  text-align: left;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.category-button:hover,
.category-button:focus-visible {
  border-color: var(--blue);
  outline: none;
}

.category-button.is-active {
  border-color: var(--green);
  background: #effaf2;
  box-shadow: inset 0 0 0 2px rgba(76, 175, 112, 0.22);
}

.category-emoji {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #fff4dc;
  font-size: 1.65rem;
}

.category-name {
  font-weight: 800;
  line-height: 1.2;
}

.category-count {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.item-list-panel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 2px solid #f0e3d4;
}

.item-list-panel h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

.item-list {
  display: grid;
  gap: 12px;
  max-height: min(48vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.item-group {
  padding: 12px;
  border: 1px solid #eadfce;
  border-radius: 8px;
  background: #fffdf8;
}

.item-group.is-selected {
  border-color: var(--green);
  background: #f3fbf6;
}

.item-group h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 1rem;
}

.item-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid #d8e6ef;
  border-radius: 8px;
  background: #f6fbff;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .stage {
    padding: 24px 16px;
  }
}

@media (max-width: 460px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding: 10px 0 18px;
    gap: 12px;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .roulette-area {
    width: min(82vw, 320px);
  }

  .history-header {
    align-items: stretch;
    flex-direction: column;
  }

  .history-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

/* LiNest v3: ルーレットと出題色は変えず、周囲の面と操作を共通化する。 */
@media screen {
  body.linest-themed .app {
    min-width: 0;
    padding-block: 28px 36px;
  }

  body.linest-themed :where(.stage, .controls) {
    min-width: 0;
    border-color: var(--linest-border);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--linest-shadow);
  }

  body.linest-themed :where(.result-panel, .history-panel, .item-group) {
    border-color: var(--linest-border);
    background: #fdfbf7;
  }

  body.linest-themed .history-panel {
    box-shadow: none;
  }

  body.linest-themed :where(.history-button, .category-button, .item-chip) {
    border-color: var(--linest-border);
    background: #ffffff;
    color: var(--linest-heading);
  }

  body.linest-themed .category-button.is-active,
  body.linest-themed .item-group.is-selected {
    border-color: var(--linest-green);
    background: var(--linest-green-soft);
  }

  body.linest-themed .category-emoji {
    background: #f6f1e8;
  }

  body.linest-themed :where(.category-button, .item-chip, .history-button) {
    min-width: 0;
    overflow-wrap: normal;
    word-break: auto-phrase;
  }
}

@media screen and (max-width: 460px) {
  body.linest-themed .app {
    padding-bottom: 28px;
  }

  body.linest-themed :where(.stage, .controls) {
    padding-inline: 14px;
  }

  body.linest-themed .history-button {
    padding-inline: 8px;
    white-space: normal;
  }
}
