:root {
  --ha-cream: #fffaf0;
  --ha-brown: #4a3728;
  --ha-green: #257836;
  --ha-green-soft: #e7f2df;
  --ha-terracotta: #c86e4a;
  --ha-border: #efe7d9;
  --ha-muted: #6f6258;
  --ha-shadow:
    0 1px 2px rgba(74, 55, 40, 0.05),
    0 4px 14px rgba(74, 55, 40, 0.07),
    0 14px 30px rgba(74, 55, 40, 0.05);
  --ha-heading-font: "Zen Maru Gothic", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

.app-shell {
  width: min(100% - 24px, 960px);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 40px) 0 48px;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.6vw, 22px);
}

.app-header,
.control-bar,
.stage,
.note {
  border: 1px solid var(--ha-border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--ha-shadow);
}

.app-header {
  padding: clamp(18px, 4vw, 32px);
}

.app-header h1 {
  margin: 4px 0 8px;
  font-family: var(--ha-heading-font);
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  line-height: 1.3;
  color: var(--ha-brown);
}

.app-header .eyebrow {
  margin: 0;
  color: var(--ha-green);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.06em;
}

.app-header .lead {
  margin: 0;
  color: var(--ha-muted);
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: clamp(12px, 2.4vw, 18px);
}

.action-button {
  flex: 1 1 auto;
  min-width: 8.5rem;
  min-height: 52px;
  padding: 10px 16px;
  border: 2px solid var(--ha-green);
  border-radius: 999px;
  background: #fff;
  color: var(--ha-green);
  font-family: var(--ha-heading-font);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.action-button:hover {
  background: var(--ha-green-soft);
}

.action-button:active {
  transform: translateY(1px);
}

.action-button.primary {
  background: var(--ha-green);
  color: #fff;
}

.action-button.primary:hover {
  background: #2f9e44;
}

.action-button.quiet {
  border-color: var(--ha-border);
  color: var(--ha-muted);
}

.action-button.quiet[aria-pressed="true"] {
  border-color: var(--ha-terracotta);
  background: #fdf0e8;
  color: var(--ha-terracotta);
}

.stage {
  position: relative;
  padding: clamp(14px, 3vw, 26px);
  overflow: hidden;
}

.motif-name {
  margin: 0 0 10px;
  font-family: var(--ha-heading-font);
  font-size: clamp(1.15rem, 3.6vw, 1.5rem);
  font-weight: 700;
  color: var(--ha-brown);
  text-align: center;
}

/* あそび場（ピースが動ける範囲）。高さは script.js が絵の大きさに合わせて決める */
.field {
  position: relative;
  width: 100%;
  min-height: 320px;
  border-radius: 22px;
  background: linear-gradient(180deg, #f6fbf2, #fdf7ec);
}

/* 完成させる場所の枠 */
.board {
  position: absolute;
  border: 3px dashed #e2d6c2;
  border-radius: 18px;
  background: #fffdf8;
}

/* ヒントのとき、うすく見せる完成図 */
.ghost {
  position: absolute;
  opacity: 0.22;
  border-radius: 18px;
  overflow: hidden;
  pointer-events: none;
}

.ghost[hidden] {
  display: none;
}

.ghost svg {
  display: block;
  width: 100%;
  height: 100%;
}

.hint-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hint-layer[hidden] {
  display: none;
}

.hint-slot {
  position: absolute;
  border: 4px dashed var(--ha-terracotta);
  border-radius: 14px;
  opacity: 0.8;
}

.pieces-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.piece {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  background: none;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  transform-origin: center center;
  box-shadow: 0 3px 6px rgba(74, 55, 40, 0.26);
}

/*
 * 共有テーマ（linest-theme.css）の `body.linest-themed button` は
 * .piece より詳細度が高く、touch-action と transition を上書きしてしまう。
 * ドラッグと回転にはどちらも必須なので、クラスを2つ重ねて勝たせる。
 */
.piece.piece {
  touch-action: none;
  transition: transform 0.14s ease;
}

.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.piece.is-dragging {
  cursor: grabbing;
  z-index: 30;
  box-shadow: 0 10px 16px rgba(74, 55, 40, 0.32);
}

/* くっついたピースは、つなぎ目が見えないように影も角丸も消す */
.piece.is-placed {
  border-radius: 0;
  box-shadow: none;
  cursor: grab;
  z-index: 10;
}

.piece.is-snapping {
  transition: left 0.18s ease, top 0.18s ease, transform 0.18s ease;
}

/* ハンドルでまわしている間は、指の動きに遅れないよう補間を切る */
.piece.is-rotating {
  transition: none;
}

/* えらばれている ピース（まわす対象）が見た目で分かるようにする */
.piece.is-selected {
  z-index: 32;
  outline: 3px dashed var(--ha-terracotta);
  outline-offset: 4px;
}

/* まわすための ハンドル（指で掴めるよう44px角）。
   丸い形と touch-action を共有テーマに上書きされないよう、クラスを2つ重ねる */
.rotate-handle.rotate-handle {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 38;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--ha-terracotta);
  border-radius: 999px;
  background: #fff;
  color: var(--ha-terracotta);
  font-size: 1.15rem;
  line-height: 1;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 3px 8px rgba(74, 55, 40, 0.28);
}

.rotate-handle[hidden] {
  display: none;
}

.rotate-handle.is-turning {
  cursor: grabbing;
  background: #fdf0e8;
}

.piece:focus-visible {
  outline: 3px solid var(--ha-terracotta);
  outline-offset: 3px;
  border-radius: 10px;
  z-index: 35;
}

.celebration {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(255, 250, 240, 0.9);
}

.celebration[hidden] {
  display: none;
}

.celebration__card {
  width: min(100%, 420px);
  padding: clamp(18px, 4vw, 30px);
  border: 1px solid var(--ha-border);
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--ha-shadow);
  text-align: center;
}

.celebration__stars {
  margin: 0;
  font-size: 1.6rem;
}

.celebration__card h2 {
  margin: 6px 0 8px;
  font-family: var(--ha-heading-font);
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  line-height: 1.3;
  color: var(--ha-brown);
}

.celebration__card p {
  margin: 0;
  color: var(--ha-muted);
}

.celebration__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.feedback {
  margin: 0;
  padding: 14px 18px;
  border: 1px solid var(--ha-border);
  border-radius: 18px;
  background: var(--ha-green-soft);
  color: var(--ha-brown);
  font-family: var(--ha-heading-font);
  font-size: 1.02rem;
  line-height: 1.5;
  text-align: center;
}

.note {
  padding: clamp(14px, 3vw, 22px);
  color: var(--ha-muted);
  font-size: 0.9rem;
}

.note p {
  margin: 0 0 6px;
}

.note p:last-child {
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .action-button {
    min-width: 7rem;
    font-size: 0.94rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action-button,
  .piece.piece,
  .piece.is-snapping {
    transition: none;
  }
}
