:root {
  --sea-top: #e6f7fc;
  --sea-bottom: #bfe6f4;
  --ink: #2f4a57;
  --muted: #6f8b97;
  --card: rgba(255, 255, 255, 0.86);
  --line: #d5ebf3;
  --fish: #5ec8f0;
  --fish-deep: #2aa6d6;
  --uni: #7d7d84;
  --pink: #ff8fab;
  --pink-soft: #ffe1e9;
  --ok: #4cc38a;
  --warn: #f2a33a;
  --danger: #e35d6a;
  --radius: 20px;
  --tap: 52px;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(180deg, var(--sea-top), var(--sea-bottom)) fixed;
  min-height: 100dvh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
h1, h2 { margin: 0 0 12px; }
h2 { font-size: 1.05rem; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }

/* 泡 */
.sea { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sea i {
  position: absolute; bottom: -40px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8); background: rgba(255, 255, 255, 0.25);
  animation: rise 14s linear infinite;
}
.sea i:nth-child(1) { left: 8%; animation-delay: 0s; }
.sea i:nth-child(2) { left: 26%; width: 9px; height: 9px; animation-delay: 4s; animation-duration: 11s; }
.sea i:nth-child(3) { left: 48%; animation-delay: 8s; animation-duration: 17s; }
.sea i:nth-child(4) { left: 67%; width: 20px; height: 20px; animation-delay: 2s; }
.sea i:nth-child(5) { left: 84%; width: 8px; height: 8px; animation-delay: 6s; animation-duration: 10s; }
.sea i:nth-child(6) { left: 93%; animation-delay: 11s; animation-duration: 15s; }
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 1; }
  50% { transform: translate(12px, -55vh); }
  100% { transform: translate(-6px, -115vh); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .sea i { animation: none; display: none; } }

.screen {
  position: relative; z-index: 1;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 6px 20px rgba(42, 166, 214, 0.12); margin-bottom: 14px;
  backdrop-filter: blur(6px);
}

/* ログイン */
#login { display: grid; place-items: center; min-height: 100dvh; padding-bottom: 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-uni { width: 150px; margin: -8px auto 0; display: block; }
.login-card h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.05em; }
.login-card form { text-align: left; margin-top: 12px; }

/* 入力 */
label { display: block; margin: 10px 0; font-size: 0.9rem; font-weight: 700; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; margin-top: 6px;
  min-height: 46px; padding: 10px 12px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--fish); }
textarea { resize: vertical; line-height: 1.6; }
input[type="range"] { padding: 0; min-height: 36px; border: 0; background: transparent; accent-color: var(--fish-deep); }
output { color: var(--fish-deep); font-weight: 800; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row > input, .row > select { margin-top: 0; }
.grow { flex: 1; min-width: 0; }
.stack > * { margin: 6px 0; }
.form-error { color: var(--danger); min-height: 1.2em; font-size: 0.88rem; margin: 8px 0 0; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; min-height: 44px; margin: 6px 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span {
  width: 50px; height: 30px; border-radius: 15px; background: #d6e3e8; position: relative; flex: none; transition: background 0.2s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--fish); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--fish-deep); outline-offset: 2px; }
.switch.small { font-size: 0.85rem; }

/* ボタン */
.btn {
  font: inherit; font-weight: 800; border: 0; cursor: pointer; color: var(--ink);
  min-height: 46px; padding: 10px 18px; border-radius: 999px; background: #fff;
  box-shadow: 0 2px 0 var(--line); transition: transform 0.08s, filter 0.2s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px) scale(0.98); box-shadow: none; }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--fish); color: #fff; box-shadow: 0 3px 0 var(--fish-deep); }
.btn.big { width: 100%; min-height: var(--tap); font-size: 1.1rem; margin-top: 12px; }
.btn.danger { background: #fff; color: var(--danger); box-shadow: 0 2px 0 #f5c7cc; }
.btn.danger.armed { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); text-decoration: underline; }
.btn.wide { width: 100%; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  background: linear-gradient(180deg, var(--sea-top) 70%, rgba(230, 247, 252, 0));
  max-width: 560px; margin: 0 auto;
}
.top-uni { width: 54px; height: 51px; object-fit: contain; }
.top-title { font-weight: 800; font-size: 1.15rem; flex: 1; letter-spacing: 0.04em; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: #fff; font-size: 0.8rem; font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); max-width: 55vw;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; background: #c4cfd4; flex: none; }
.pill.online .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(76, 195, 138, 0.2); }
.pill.offline .dot { background: var(--warn); }
.pill.nolink .dot { background: var(--danger); }
#conn-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 窓 */
.window-wrap { position: relative; width: min(78vw, 340px); aspect-ratio: 1; margin: 6px auto 18px; }
.window-circle {
  width: 100%; height: 100%; border-radius: 50%; overflow: hidden; position: relative;
  background: radial-gradient(circle at 50% 35%, #1d3b5c, #0b1a2c 75%);
  border: 10px solid #fff; box-shadow: 0 10px 30px rgba(42, 166, 214, 0.3), inset 0 0 30px rgba(0, 0, 0, 0.5);
  color: #e8f6ff; display: grid; place-items: center; text-align: center;
}
.live-text { padding: 18%; font-size: 0.85rem; line-height: 1.6; }
.live-text .scene { font-size: 1.25rem; font-weight: 800; margin: 4px 0; }
.live-text .meta { opacity: 0.7; font-size: 0.75rem; }
.live-text pre { margin: 6px 0 0; font-size: 0.65rem; opacity: 0.65; white-space: pre-wrap; word-break: break-all; max-height: 4.5em; overflow: hidden; }
.window-circle.asleep { filter: saturate(0.6) brightness(0.8); }

/* 演出 */
.fx { position: absolute; inset: 0; pointer-events: none; }
.fx .swim { position: absolute; width: 70px; top: 45%; left: -80px; animation: swim 2.4s ease-in-out forwards; }
@keyframes swim {
  0% { transform: translate(0, 0) rotate(-4deg); }
  25% { transform: translate(28vw, -14px) rotate(3deg); }
  50% { transform: translate(52vw, 6px) rotate(-3deg); }
  100% { transform: translate(min(110vw, 480px), -10px) rotate(4deg); opacity: 0.2; }
}
.fx .bubble { position: absolute; bottom: 20%; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; animation: pop 1.6s ease-out forwards; }
@keyframes pop { to { transform: translateY(-140px) scale(1.4); opacity: 0; } }
.fx .heart { position: absolute; left: 50%; top: 50%; font-size: 30px; color: var(--pink); animation: burst 1.6s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(1.6); opacity: 0; } }
.fx .knock { position: absolute; inset: 0; border-radius: 50%; border: 6px solid var(--pink); animation: ripple 1s ease-out forwards; }
@keyframes ripple { from { transform: scale(0.9); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
.fx .uni-pop { position: absolute; left: 50%; top: 50%; width: 160px; transform: translate(-50%, -50%); animation: unipop 2.2s ease-out forwards; }
@keyframes unipop { 0% { transform: translate(-50%, -30%) scale(0.3); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%, -70%) scale(1); opacity: 0; } }

/* 大きなボタン */
.actions { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 12px; align-items: center; }
.btn.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  aspect-ratio: 1; border-radius: 28px; padding: 8px; font-size: 0.85rem; background: #fff;
  box-shadow: 0 4px 0 var(--line), 0 8px 18px rgba(42, 166, 214, 0.15);
}
.btn.action img { width: 64%; border-radius: 10px; }
.btn.action .emoji { font-size: 2rem; line-height: 1; color: var(--fish-deep); }
.btn.action.press {
  border-radius: 50%; position: relative; background: radial-gradient(circle at 35% 30%, #fff, var(--pink-soft));
  color: #d94f78; font-size: 1rem; box-shadow: 0 5px 0 #f7bccb, 0 10px 24px rgba(255, 143, 171, 0.35);
}
.press-label { position: relative; z-index: 1; line-height: 1.3; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke: var(--pink); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 340; stroke-dashoffset: 340; }
.btn.press.waiting .ring circle { animation: ring 3s linear forwards; }
@keyframes ring { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 340; } }
.btn.press.waiting { animation: throb 0.6s ease-in-out infinite alternate; }
@keyframes throb { to { transform: scale(1.05); } }
.btn.press.matched { background: var(--pink); color: #fff; }
.hint { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 10px 0 16px; min-height: 1.2em; }

.today-row { display: flex; align-items: center; gap: 16px; }
.label { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.big-num { font-size: 2rem; font-weight: 800; color: var(--pink); line-height: 1.1; }
.big-num small { font-size: 0.9rem; margin-left: 2px; }
.today-last { flex: 1; }
.today-weather { text-align: right; font-size: 0.85rem; }
.today-weather .w-ico { font-size: 1.8rem; display: block; line-height: 1; }

/* リスト */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 2px; border-bottom: 1px dashed var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { overflow-wrap: anywhere; }
.list .when { font-size: 0.75rem; color: var(--muted); }
.list .empty { color: var(--muted); justify-content: center; }
.list button.btn { min-height: 38px; padding: 6px 14px; font-size: 0.85rem; }
.badge { font-size: 0.72rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: #eef4f6; color: var(--muted); white-space: nowrap; }
.badge.read { background: var(--pink-soft); color: #d94f78; }
.badge.delivered { background: #dff5ea; color: #2f9a68; }
.badge.queued { background: #fff2dc; color: #b9741c; }
.badge.pending { background: #e1f3fb; color: var(--fish-deep); }
.history .ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--pink-soft); flex: none; }
.history .day { font-size: 0.8rem; color: var(--muted); font-weight: 800; padding: 14px 2px 4px; border: 0; }
details.sub { margin-top: 10px; }
details.sub summary { cursor: pointer; font-weight: 700; color: var(--fish-deep); min-height: 40px; display: flex; align-items: center; }

/* 設定 */
.screens { list-style: none; padding: 0; margin: 0 0 8px; }
.screens li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 14px; background: #f5fbfd; margin: 6px 0; }
.screens li.off { opacity: 0.55; }
.screens .name { flex: 1; font-weight: 700; }
.screens button { min-width: 44px; min-height: 44px; border-radius: 12px; border: 0; background: #fff; font: inherit; font-weight: 800; color: var(--ink); }
.screens button.on { background: var(--fish); color: #fff; }
.loc-current { font-weight: 800; margin-bottom: 6px; }
.save-bar {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 4; display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 10px 14px; margin-bottom: 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.95); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 0.88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.secret { margin-top: 10px; padding: 12px; border-radius: 14px; background: #fff8e6; font-family: ui-monospace, monospace; font-size: 0.8rem; word-break: break-all; }
.secret button { margin-top: 8px; }

/* 下のタブ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 -4px 16px rgba(42, 166, 214, 0.12); border-radius: 22px 22px 0 0;
  max-width: 560px; margin: 0 auto;
}
.tabs button {
  font: inherit; font-size: 0.72rem; font-weight: 800; color: var(--muted); background: none; border: 0;
  min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 16px;
}
.tabs .ico { font-size: 1.3rem; line-height: 1; }
.tabs button.on { color: var(--fish-deep); background: #e7f6fc; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  .window-wrap { width: 340px; }
}
