:root {
  color-scheme: dark;
  --bg: #130b0b;
  --surface: #211614;
  --surface-2: #2e1f1b;
  --surface-3: #3a1717;
  --ink: #f8efe3;
  --muted: #c8aa91;
  --line: #623329;
  --green: #b72a2f;
  --green-2: #391313;
  --coral: #e45b43;
  --amber: #c99a47;
  --violet: #d7b269;
  --gold: #d5ad64;
  --gold-2: #f2dca8;
  --black-lacquer: #090606;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: rgba(213, 173, 100, 0.18);
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.schedule-list {
  display: grid;
  gap: 10px;
}

.schedule-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
}

.schedule-row div:first-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.schedule-row span,
.schedule-row small {
  overflow-wrap: anywhere;
}

.schedule-row small {
  color: var(--muted);
}

.intel-list,
.diary-list,
.call-list,
.call-stream {
  display: grid;
  gap: 10px;
}

.intel-row,
.diary-entry,
.call-message,
.call-tab {
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
  padding: 12px;
}

.intel-row,
.call-tab {
  display: grid;
  gap: 4px;
  text-align: left;
  color: var(--ink);
}

.intel-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.intel-row div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.call-tab {
  width: 100%;
  cursor: pointer;
}

.call-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.call-tab.active {
  border-color: rgba(228, 91, 67, 0.72);
  background: rgba(94, 20, 22, 0.5);
}

.intel-row span,
.diary-entry p,
.call-message p {
  overflow-wrap: anywhere;
}

.intel-row small,
.diary-entry small,
.call-tab small {
  color: var(--muted);
}

.diary-entry header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.diary-entry header span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.diary-entry p,
.call-message p {
  margin: 8px 0 0;
  line-height: 1.65;
}

.call-message.user {
  border-color: rgba(201, 154, 71, 0.42);
}

.call-message.assistant {
  border-color: rgba(183, 42, 47, 0.5);
}

.call-message audio {
  width: 100%;
  margin-top: 8px;
}

.phase-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
}

.phase-head h3,
.phase-log-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.phase-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.phase-card,
.phase-log {
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
  padding: 12px;
}

.phase-log-list {
  display: grid;
  gap: 10px;
}

.phase-log {
  display: grid;
  gap: 4px;
}

.phase-log span {
  overflow-wrap: anywhere;
}

.phase-log small {
  color: var(--muted);
}

.worldbook-list {
  display: grid;
  gap: 12px;
}

.worldbook-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
}

.proactive-call-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
}

.proactive-call-box h3 {
  margin: 0;
  font-size: 1rem;
}

.storage-view.active {
  display: grid;
  gap: 16px;
}

.storage-summary,
.storage-actions,
.storage-breakdown {
  display: grid;
  gap: 10px;
}

.storage-total {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
}

.storage-total b {
  color: var(--gold-2);
  font-size: 1.8rem;
}

.storage-total.compact b {
  font-size: 1.1rem;
}

.storage-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
}

.storage-row div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.storage-row span,
.storage-total small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.storage-row strong {
  color: var(--gold-2);
}

.storage-row i {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--red-2) var(--fill), rgba(255, 255, 255, 0.08) var(--fill));
}

.incoming-call-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 2, 2, 0.72);
  backdrop-filter: blur(8px);
}

.incoming-call-modal.hidden {
  display: none;
}

.incoming-call-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid rgba(216, 178, 88, 0.42);
  background: radial-gradient(circle at top, rgba(124, 23, 26, 0.92), rgba(13, 8, 8, 0.96) 58%);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.incoming-call-mark {
  color: var(--gold-2);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.incoming-call-card h3,
.incoming-call-card p,
.incoming-call-card blockquote {
  margin: 0;
}

.incoming-call-card blockquote {
  padding: 12px;
  border-left: 3px solid var(--red-2);
  background: rgba(0, 0, 0, 0.24);
  line-height: 1.6;
}

.sync-health {
  display: grid;
  gap: 8px;
}

.sync-health-panel {
  align-content: start;
}

.sync-actions {
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.sync-actions button {
  flex: 1 1 120px;
}

.sync-empty,
.sync-meta,
.sync-head,
.sync-row {
  border: 1px solid rgba(216, 178, 88, 0.24);
  background: rgba(18, 10, 10, 0.52);
  padding: 10px 12px;
}

.sync-empty {
  color: var(--muted);
  line-height: 1.6;
}

.sync-empty.error {
  color: var(--coral);
}

.sync-meta {
  display: grid;
  gap: 4px;
}

.sync-meta b {
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.sync-meta small {
  color: var(--muted);
}

.sync-head,
.sync-row {
  display: grid;
  grid-template-columns: minmax(88px, 1fr) minmax(56px, auto) minmax(64px, auto) minmax(54px, auto);
  gap: 10px;
  align-items: center;
}

.sync-head {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
}

.sync-row span,
.sync-row b,
.sync-row small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sync-row b {
  font-size: 0.86rem;
}

.sync-row small {
  justify-self: end;
  color: var(--gold-2);
}

.sync-row.warn {
  border-color: rgba(228, 91, 67, 0.55);
}

.sync-row.warn small {
  color: var(--coral);
}

@media (display-mode: standalone) {
  .topbar {
    padding-top: max(18px, env(safe-area-inset-top));
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  background:
    linear-gradient(90deg, rgba(8, 5, 5, 0.96), rgba(28, 12, 12, 0.92)),
    url("data:image/svg+xml,%3Csvg width='180' height='180' viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%2366382d' stroke-width='1' opacity='.38'%3E%3Cpath d='M0 40c20 20 40 20 60 0s40-20 60 0 40 20 60 0M0 80c20 20 40 20 60 0s40-20 60 0 40 20 60 0M0 120c20 20 40 20 60 0s40-20 60 0 40 20 60 0'/%3E%3Cpath d='M30 0v180M90 0v180M150 0v180' opacity='.25'/%3E%3C/g%3E%3C/svg%3E");
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

input,
textarea,
select {
  font-size: 16px;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(10, 6, 6, 0.97), rgba(35, 15, 14, 0.94)),
    url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23a83a33' stroke-width='1' opacity='.22'%3E%3Cpath d='M0 0h80v80H0zM40 0v80M0 40h80'/%3E%3Ccircle cx='40' cy='40' r='18'/%3E%3C/g%3E%3C/svg%3E");
  backdrop-filter: blur(18px);
}

.brand,
.thread,
.sidebar-footer,
.panel-head,
.topbar,
.composer,
.memory-header,
.button-row,
.memory-actions,
.top-actions,
.persona-controls {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 0;
  border: 0;
  background: transparent;
  color: #050202;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.oda-mon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand strong,
.thread b,
.panel h2,
.topbar h1,
.memory-header h2 {
  display: block;
  margin: 0;
}

.brand span,
.thread small,
.topbar p,
.memory-header p,
.section-kicker {
  color: var(--muted);
}

.brand strong {
  color: var(--gold-2);
  font-size: 18px;
  letter-spacing: 0.04em;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item,
.thread,
.icon-button,
.ghost-button,
.primary-button,
.text-button,
.composer-tools button,
.send-button,
.search-bar button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
}

.nav-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  text-align: left;
}

.nav-item span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 7px;
  border: 1px solid rgba(213, 173, 100, 0.25);
  background: var(--black-lacquer);
  color: var(--gold-2);
}

.nav-item.active,
.thread.active {
  border-color: rgba(213, 173, 100, 0.5);
  background: linear-gradient(90deg, rgba(128, 24, 27, 0.72), rgba(53, 19, 19, 0.88));
  box-shadow: inset 3px 0 0 var(--gold);
}

.conversation-list {
  display: grid;
  gap: 9px;
}

.section-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.thread {
  gap: 10px;
  width: 100%;
  padding: 11px;
  text-align: left;
}

.thread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  flex: 0 0 auto;
}

.thread-dot.coral {
  background: var(--coral);
}

.thread-dot.violet {
  background: var(--violet);
}

.sidebar-footer {
  justify-content: space-between;
  margin-top: auto;
  gap: 10px;
}

.pill,
.metric {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--green-2);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.pill.muted {
  background: var(--surface-2);
  color: var(--muted);
}

.metric {
  background: rgba(213, 173, 100, 0.14);
  color: var(--gold-2);
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: block;
  margin-bottom: 18px;
}

.top-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.topbar h1 {
  font-size: 30px;
  color: var(--gold-2);
  letter-spacing: 0.03em;
}

.topbar p {
  margin: 4px 0 0;
}

.top-kamon {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-bottom: 6px;
  padding: 0 9px;
  border: 1px solid rgba(213, 173, 100, 0.38);
  border-radius: 999px;
  background: rgba(183, 42, 47, 0.18);
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.top-actions,
.button-row,
.memory-actions {
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  margin-top: 6px;
}

.ghost-button,
.primary-button,
.text-button,
.icon-button {
  min-height: 38px;
  padding: 0 14px;
  font-weight: 800;
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  border-color: rgba(213, 173, 100, 0.4);
  background: linear-gradient(180deg, #c13a3e, #8e171c);
  color: var(--gold-2);
  box-shadow: inset 0 1px 0 rgba(255, 245, 211, 0.18);
}

.text-button {
  color: var(--gold);
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--surface-2);
  color: var(--gold-2);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.content-grid.active {
  display: grid;
}

.content-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  min-height: calc(100vh - 112px);
}

.chat-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(34, 22, 20, 0.94), rgba(24, 14, 13, 0.96)),
    url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23d8b166' opacity='.06'%3E%3Cpath d='M0 0h1v120H0zM30 0h1v120h-1zM60 0h1v120h-1zM90 0h1v120h-1zM0 0v1h120V0zM0 30v1h120v-1zM0 60v1h120v-1zM0 90v1h120v-1z'/%3E%3C/g%3E%3C/svg%3E");
  box-shadow: var(--shadow);
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 640px;
  overflow: hidden;
}

.message-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  overflow: auto;
  position: relative;
}

.message-stream.empty {
  justify-content: center;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 42%, rgba(201, 0, 23, 0.34), transparent 34%),
    linear-gradient(135deg, rgba(8, 4, 4, 0.72), rgba(50, 14, 13, 0.42));
}

.honmaru-screen {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 260px;
}

.honmaru-crest {
  width: min(300px, 64%);
  aspect-ratio: 1;
  background: transparent;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.34);
}

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

.honmaru-label {
  color: var(--gold-2);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.message {
  max-width: min(720px, 92%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.message.assistant {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  background: rgba(82, 22, 20, 0.92);
  border-color: rgba(213, 173, 100, 0.32);
}

.message .role {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-role-button,
.message-delete {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.message-role-button {
  padding: 0;
  cursor: pointer;
}

.message-role-button:hover {
  color: var(--gold-2);
}

.message-delete {
  display: none;
}

.message-action-menu {
  position: fixed;
  z-index: 80;
  min-width: 128px;
  padding: 6px;
  border: 1px solid rgba(216, 178, 88, 0.36);
  border-radius: 8px;
  background: rgba(12, 7, 7, 0.96);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
}

.message-action-menu.hidden {
  display: none;
}

.message-action-menu button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: rgba(116, 22, 24, 0.76);
  color: var(--gold-2);
  font-weight: 800;
  cursor: pointer;
}

.message-action-menu button:hover {
  background: rgba(168, 42, 47, 0.92);
}

.message p {
  margin: 0;
  line-height: 1.58;
}

.message audio {
  width: 100%;
  margin-top: 10px;
}

.voice-message {
  min-width: min(360px, 92%);
}

.voice-bar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 54px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(216, 178, 88, 0.34);
  background: linear-gradient(90deg, rgba(93, 20, 22, 0.78), rgba(20, 12, 12, 0.88));
}

.voice-play {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(216, 178, 88, 0.5);
  background: rgba(8, 5, 5, 0.82);
  color: var(--gold-2);
  font-weight: 900;
  cursor: pointer;
}

.voice-bar div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.voice-bar b,
.voice-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-bar span {
  color: var(--muted);
  font-size: 12px;
}

.voice-bar audio {
  display: none;
}

.composer {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(12, 7, 7, 0.82);
}

.composer-tools {
  display: flex;
  gap: 6px;
}

.composer-tools button,
.send-button,
.search-bar button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--surface-2);
  color: var(--gold-2);
}

.composer textarea {
  width: 100%;
  max-height: 160px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
}

.send-button {
  background: var(--black-lacquer);
  color: var(--gold-2);
}

.right-rail {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel {
  padding: 16px;
}

.panel.compact {
  min-height: 310px;
}

.panel-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 17px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

.status-dot.idle {
  background: var(--amber);
}

.tool-feed,
.memory-surface,
.memory-results,
.bucket-list,
.bucket-detail {
  display: grid;
  gap: 10px;
}

.tool-event,
.memory-card,
.bucket-card,
.tool-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 10, 10, 0.58);
  padding: 12px;
}

.tool-event b,
.memory-card b,
.bucket-card b,
.tool-card b {
  display: block;
  margin-bottom: 5px;
}

.tool-event span,
.memory-card span,
.bucket-card span,
.tool-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.inner-voice {
  display: grid;
  gap: 10px;
}

.inner-voice-panel {
  display: none;
  position: fixed;
  top: 92px;
  right: 22px;
  z-index: 40;
  width: min(360px, calc(100vw - 28px));
  max-height: min(520px, calc(100dvh - 130px));
  overflow: auto;
}

.inner-voice-open .inner-voice-panel {
  display: block;
}

.inner-card {
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  background: rgba(213, 173, 100, 0.12);
  padding: 11px 12px;
}

.inner-card b {
  display: block;
  margin-bottom: 5px;
  color: var(--gold-2);
  font-size: 12px;
}

.inner-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.inner-voice-off .inner-voice-panel {
  display: none;
}

.memory-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.memory-header h2 {
  font-size: 24px;
}

.memory-header p {
  margin: 4px 0 0;
}

.memory-layout {
  display: grid;
  grid-template-columns: 320px minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.connect-panel,
.search-panel {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(213, 173, 100, 0.28);
  border-color: var(--gold);
}

.search-bar {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.bucket-panel {
  grid-column: 1 / 3;
}

.detail-panel {
  grid-column: 3;
  grid-row: 1 / span 3;
  min-height: 520px;
}

.bucket-list {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.bucket-card {
  text-align: left;
}

.bucket-card button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}

.bucket-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.bucket-tags em {
  border-radius: 999px;
  background: var(--surface-2);
  padding: 4px 8px;
  color: var(--gold-2);
  font-size: 12px;
  font-style: normal;
}

.bucket-detail {
  color: var(--ink);
  line-height: 1.65;
  white-space: pre-wrap;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.tool-card {
  min-height: 150px;
}

.tool-card .switch {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.persona-view.active {
  display: grid;
  max-width: 860px;
}

.persona-editor {
  display: grid;
  gap: 14px;
}

.persona-controls {
  flex-wrap: wrap;
  gap: 16px;
}

.persona-controls label {
  grid-template-columns: auto 1fr;
  color: var(--ink);
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(6, 4, 4, 0.74);
}

.dialog-card {
  display: grid;
  min-width: min(520px, calc(100vw - 32px));
  gap: 14px;
  padding: 20px;
  background: var(--surface);
}

.dialog-card h2 {
  margin: 0;
}

.dialog-card menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.connection-test {
  display: grid;
  gap: 10px;
}

.connection-test .sync-empty {
  margin: 0;
  white-space: pre-line;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.full {
  width: 100%;
}

.slim {
  min-height: 32px;
  padding: 0 10px;
}

.thread-list,
.workflow-steps,
.runtime-summary,
.permission-grid {
  display: grid;
  gap: 10px;
}

.permission-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.thread-row {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  gap: 6px;
}

.thread-row .thread {
  min-width: 0;
}

.danger,
.danger-text {
  color: var(--coral);
}

.chat-options {
  display: grid;
  grid-template-columns: 150px repeat(2, minmax(150px, auto)) auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 7, 7, 0.72);
}

.nav-item:hover,
.thread:hover,
.ghost-button:hover,
.icon-button:hover,
.composer-tools button:hover,
.search-bar button:hover {
  border-color: rgba(213, 173, 100, 0.42);
  background: rgba(213, 173, 100, 0.08);
}

.primary-button:hover,
.send-button:hover {
  filter: brightness(1.08);
}

::placeholder {
  color: rgba(200, 170, 145, 0.68);
}

.inline-check,
.tool-title-row,
.workflow-step {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inline-check input,
.persona-controls input,
.compact-switch input {
  width: auto;
}

.runtime-summary div {
  display: grid;
  gap: 3px;
}

.runtime-summary b {
  color: var(--muted);
  font-size: 12px;
}

.runtime-summary span {
  overflow-wrap: anywhere;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.tool-section {
  margin-top: 0;
}

.tool-title-row {
  justify-content: space-between;
}

.tool-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.compact-switch {
  grid-template-columns: auto auto;
  color: var(--ink);
  font-size: 12px;
}

.workflow-step span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 800;
}

.workflow-step input {
  flex: 1;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.bucket-detail pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}

.write-panel {
  display: grid;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 12px;
}

.context-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .brand div:not(.brand-mark),
  .nav-item b,
  .conversation-list,
  .sidebar-footer .pill {
    display: none;
  }

  .sidebar {
    align-items: center;
    padding: 18px;
  }

  .nav-item {
    grid-template-columns: 1fr;
  }

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

  .right-rail {
    grid-template-columns: 1fr 1fr;
  }

  .memory-layout,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .detail-panel {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

@media (max-width: 760px) {
  :root {
    --mobile-nav-height: 68px;
    --mobile-composer-height: 76px;
  }

  body {
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    flex-direction: row;
    justify-content: space-between;
    gap: 0;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 -16px 38px rgba(0, 0, 0, 0.45);
  }

  .brand,
  .conversation-list,
  .sidebar-footer {
    display: none;
  }

  .nav-stack {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: 100%;
    gap: 4px;
  }

  .nav-item {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 48px;
    padding: 4px 2px;
    border-radius: 8px;
    font-size: 11px;
  }

  .nav-item span {
    width: 30px;
    height: 30px;
    font-size: 18px;
  }

  .nav-item b {
    display: block;
    max-width: 100%;
    font-size: 10px;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-item.active {
    box-shadow: inset 0 2px 0 var(--gold);
  }

  .workspace {
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 8px calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 10px);
  }

  .topbar,
  .memory-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .topbar {
    display: block;
    padding-top: 0;
  }

  .topbar h1 {
    font-size: 22px;
    line-height: 1.18;
  }

  .topbar p,
  .memory-header p {
    font-size: 13px;
    line-height: 1.45;
  }

  .top-actions,
  .memory-actions {
    width: 100%;
    gap: 8px;
  }

  .top-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .top-actions button {
    flex: 0 0 auto;
    min-width: auto;
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .chat-panel {
    min-height: calc(100dvh - var(--mobile-nav-height) - env(safe-area-inset-bottom) - 80px);
    padding-bottom: 0;
    overflow: hidden;
  }

  .content-grid.active {
    gap: 10px;
    min-height: calc(100dvh - var(--mobile-nav-height) - env(safe-area-inset-bottom) - 76px);
  }

  .message-stream {
    min-height: calc(100dvh - var(--mobile-nav-height) - var(--mobile-composer-height) - env(safe-area-inset-bottom) - 160px);
    max-height: calc(100dvh - var(--mobile-nav-height) - var(--mobile-composer-height) - env(safe-area-inset-bottom) - 112px);
    overflow-y: auto;
    padding: 12px 12px calc(var(--mobile-composer-height) + 14px);
    gap: 12px;
  }

  .message {
    max-width: 96%;
    padding: 12px 13px;
  }

  .honmaru-screen {
    min-height: 160px;
  }

  .honmaru-crest {
    width: min(180px, 58%);
  }

  .right-rail,
  .memory-layout,
  .settings-grid,
  .chat-options,
  .phase-grid {
    grid-template-columns: 1fr;
  }

  .right-rail {
    gap: 12px;
  }

  .panel.compact,
  .detail-panel {
    min-height: auto;
  }

  .bucket-panel,
  .detail-panel {
    grid-column: auto;
  }

  .chat-options {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 10px;
    scrollbar-width: none;
  }

  .chat-options::-webkit-scrollbar {
    display: none;
  }

  .chat-options label,
  .chat-options button {
    flex: 0 0 auto;
  }

  .chat-options select {
    min-width: 96px;
  }

  .chat-options .inline-check {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    gap: 6px;
    padding: 0 8px;
    border: 1px solid rgba(216, 178, 88, 0.2);
    border-radius: 8px;
    background: rgba(18, 10, 10, 0.52);
    white-space: nowrap;
  }

  .chat-options .inline-check input {
    width: 18px;
    height: 18px;
  }

  .composer {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 6px);
    z-index: 28;
    align-items: end;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    min-height: var(--mobile-composer-height);
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.28);
  }

  .composer textarea {
    min-height: 44px;
    max-height: 90px;
  }

  .composer-tools {
    display: flex;
    gap: 0;
  }

  .composer-tools button,
  .send-button,
  .search-bar button,
  .icon-button,
  .ghost-button,
  .primary-button,
  .text-button {
    min-height: 44px;
  }

  .inner-voice-panel {
    top: max(68px, calc(env(safe-area-inset-top) + 48px));
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100dvh - var(--mobile-nav-height) - var(--mobile-composer-height) - env(safe-area-inset-bottom) - 96px);
  }

  .form-grid,
  .context-grid,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .tool-grid,
  .bucket-list {
    grid-template-columns: 1fr;
  }

  .sync-head,
  .sync-row {
    grid-template-columns: minmax(86px, 1fr) minmax(0, 1fr);
  }

  .sync-head b:nth-of-type(2),
  .sync-row b:nth-of-type(2) {
    display: none;
  }

  .sync-head small,
  .sync-row small {
    justify-self: start;
  }

  .dialog-card {
    min-width: min(100vw - 24px, 520px);
    max-height: calc(100dvh - 28px);
    overflow: auto;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding-left: 6px;
    padding-right: 6px;
  }

  .composer {
    left: 6px;
    right: 6px;
  }

  .panel,
  .chat-panel {
    border-radius: 8px;
  }

  .panel {
    padding: 12px;
  }

  .button-row,
  .memory-actions {
    flex-wrap: nowrap;
  }

  .button-row button,
  .memory-actions button {
    flex: 1 1 auto;
  }

  .phase-head,
  .panel-head,
  .diary-entry header {
    align-items: flex-start;
    flex-direction: column;
  }
}
