:root {
  --ink: #1d1d2b;
  --muted: #6b6b80;
  --line: #e4e2ec;
  --paper: #f6f4ef;
  --card: #ffffff;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --radius: 18px;
  --gap: 10px;
  font-family: 'M PLUS Rounded 1c', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- 共通パーツ ---------- */

.btn {
  border: 2px solid var(--ink);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  transition: transform .08s ease, box-shadow .08s ease;
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.25rem; padding: 14px 34px; }
.btn.small { padding: 4px 12px; font-size: .85rem; box-shadow: 0 2px 0 var(--ink); }

.avatar {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.7); border: 2px solid var(--ink);
  font-size: 17px; line-height: 1; overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 36px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; height: 58px;
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--ink); letter-spacing: .02em; }
.room-info { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.count { font-weight: 800; font-variant-numeric: tabular-nums; }
.me-btn {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--card);
  padding: 3px 14px 3px 3px; font-weight: 700; max-width: 220px;
}
.home .me-btn { margin-left: auto; }
.me-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hint { color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); font-size: .9rem; }

/* ---------- トップページ ---------- */

.hero {
  max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; text-align: center;
}
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.25; margin: 28px 0 12px; font-weight: 800; }
.lead { color: var(--muted); font-size: 1.05rem; line-height: 1.8; margin: 0 auto 28px; max-width: 30em; }
.hero-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  max-width: 420px; margin: 0 auto; aspect-ratio: 16 / 10;
  padding: 8px; background: var(--ink); border-radius: 22px;
}
.hero-grid > div {
  background: var(--c); border-radius: 14px; padding: 12px; text-align: left; font-weight: 700;
}
.join { display: flex; gap: 8px; max-width: 420px; margin: 26px auto 10px; }
.join input {
  flex: 1; min-width: 0; border: 2px solid var(--ink); border-radius: 999px; padding: 8px 16px; background: var(--card);
}

/* ---------- ルーム ---------- */

body.room { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.board {
  flex: 1; min-height: 0;
  display: grid; gap: var(--gap); padding: 0 var(--gap) var(--gap);
  grid-template-columns: 1fr; grid-template-rows: 1fr;
}
.board[data-count="2"] { grid-template-columns: 1fr 1fr; }
.board[data-count="3"],
.board[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.board[data-count="3"] > .panel:nth-child(3) { grid-column: 1 / -1; }

/* 縦長画面では2人のときは上下に並べる */
@media (max-aspect-ratio: 1/1) {
  .board[data-count="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

.panel {
  --bg: #ffffff;
  --fg: var(--ink);
  position: relative; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  border: 2px solid var(--ink); border-radius: var(--radius);
  transition: background-color .25s ease;
  overflow: hidden;
}
.panel.dark { --fg: #f4f2ff; }
.panel.self { box-shadow: 0 0 0 3px var(--accent); }

.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 0; font-weight: 700; min-width: 0;
}
.panel-header .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  font-size: .7rem; padding: 1px 8px; border-radius: 999px;
  background: var(--accent); color: #fff; flex: none;
}
.tag.soft { background: transparent; color: inherit; border: 1.5px solid currentColor; opacity: .55; }

.typing { display: none; gap: 3px; margin-left: 2px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: bounce 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
.is-typing .typing { display: inline-flex; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

.panel-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 8px 20px 16px;
  overflow-y: auto;
}
.self .panel-body { padding-bottom: 52px; }
/* 上下中央・左寄せ（溢れた時に上が切れないよう margin で中央寄せ） */
.panel-text {
  margin: auto 0; width: 100%; padding: 0;
  border: 0; outline: 0; resize: none; overflow: hidden; background: transparent; color: inherit;
  font-size: 32px; line-height: 1.3; text-align: left;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.panel-text::placeholder { color: currentColor; opacity: .35; }
.placeholder { opacity: .35; }

.caret {
  display: inline-block; width: 2px; height: 1.15em; margin: 0 -1px;
  vertical-align: text-bottom; background: var(--accent);
  animation: blink 1s steps(1) infinite;
}
.is-typing .caret { animation: none; }
@keyframes blink { 50% { opacity: 0; } }

.panel-tools {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; gap: 6px; align-items: flex-end;
}
.btn.tool { font-size: .8rem; padding: 4px 12px; box-shadow: 0 2px 0 var(--ink); background: var(--card); color: var(--ink); }
.btn.tool.heart { position: relative; font-size: 1rem; padding: 2px 10px; }
.btn.tool.heart.pop { animation: heart-pop .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes heart-pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.45) rotate(-8deg); }
  60% { transform: scale(.9) rotate(4deg); }
  100% { transform: scale(1); }
}
.combo {
  position: absolute; left: 50%; bottom: 100%; margin-bottom: 4px; transform: translateX(-50%);
  font-size: .8rem; font-weight: 800; color: var(--accent); white-space: nowrap; pointer-events: none;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.combo.bump { animation: combo-bump .35s ease-out; }
@keyframes combo-bump { 0% { transform: translateX(-50%) scale(1.8); } 100% { transform: translateX(-50%) scale(1); } }

.heart-layer { position: fixed; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.heart-particle {
  position: absolute; line-height: 1; will-change: transform, opacity;
  filter: drop-shadow(0 2px 4px rgba(255, 60, 110, .35));
}
.heart-ring {
  position: absolute; width: 60px; height: 60px; border-radius: 50%;
  border: 3px solid #ff5c8a; pointer-events: none;
}

/* 相手のパネルのハートは下中央 */
.panel-tools.centered { right: auto; left: 50%; transform: translateX(-50%); }

.mic-group { display: flex; align-items: flex-end; gap: 4px; }
.btn.tool.mic.on {
  background: var(--accent); color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { box-shadow: 0 2px 0 var(--ink), 0 0 0 0 rgba(255,107,74,.55); } 50% { box-shadow: 0 2px 0 var(--ink), 0 0 0 8px rgba(255,107,74,0); } }
.mic-lang {
  border: 2px solid var(--ink); border-radius: 999px; background: var(--card); color: var(--ink);
  font-size: .75rem; font-weight: 700; padding: 3px 4px; height: 28px; cursor: pointer;
}
.palette {
  position: absolute; right: 0; bottom: 42px; width: 214px;
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px;
  background: var(--card); border: 2px solid var(--ink); border-radius: 14px;
}
.palette[hidden] { display: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); padding: 0;
}
.swatch.active { outline: 3px solid var(--accent); outline-offset: 1px; }
.swatch-custom {
  width: 30px; height: 30px; border: 2px solid var(--ink); border-radius: 50%; padding: 0; background: none; cursor: pointer;
}
.swatch-custom::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-custom::-webkit-color-swatch { border: 0; border-radius: 50%; }

/* 1人のときは招待を促す */
.board.show-help.alone::after {
  content: 'Share the link to invite friends (up to 4)';
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: .85rem; padding: 6px 14px; border-radius: 999px;
  pointer-events: none; white-space: nowrap;
}

.toast {
  position: fixed; top: 66px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-size: .9rem; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

.notice {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(29,29,43,.5); z-index: 30; padding: 16px;
}
.notice-card {
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: 28px; text-align: center; max-width: 360px;
}
.notice-card h2 { margin-top: 0; }

/* ---------- モーダル ---------- */

.modal {
  border: 2px solid var(--ink); border-radius: var(--radius); padding: 0;
  width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--ink);
}
.modal::backdrop { background: rgba(29,29,43,.45); }
.modal-body { position: relative; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-close {
  position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 1.5rem; line-height: 1;
}
.tabs { display: flex; gap: 4px; padding-right: 28px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 6px 4px; font-weight: 700; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button.active { color: var(--ink); border-color: var(--accent); }
.profile-head { display: flex; align-items: center; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: .9rem; }
.field input:not([type=color]):not([type=file]) {
  border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 400;
}
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.avatar-pick {
  aspect-ratio: 1; border: 2px solid var(--line); border-radius: 12px; background: none;
  font-size: 20px; display: grid; place-items: center; cursor: pointer;
}
.avatar-pick.active { border-color: var(--accent); background: #fff1ed; }
.error { color: #d0342c; margin: 0; font-size: .9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal .hint { margin: 0; }
.share-modal h2 { margin: 0; font-size: 1.3rem; }
.share-modal p { margin: 0; }
.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1; min-width: 0; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px;
  background: var(--paper); font-size: .9rem;
}

@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand { font-size: 1rem; }
  #copy { font-size: 0; padding: 4px 10px; }
  #copy::before { content: '🔗 Invite'; font-size: .8rem; }
  .me-btn { padding: 3px; }
  .me-btn span:last-child { display: none; }
  .board { --gap: 6px; }
  .btn.tool .label { display: none; }
  .btn.tool.mic.on .label { display: inline; }
  .panel-header { padding: 8px 10px 0; font-size: .85rem; }
  .panel-header .avatar { width: 24px; height: 24px; font-size: 14px; }
  .panel-body { padding: 6px 12px 12px; }
  .self .panel-body { padding-bottom: 44px; }
}
