:root {
  --bg: #0e1217;
  --panel: #161d26;
  --panel-soft: #101720;
  --border: #263241;
  --accent: #22c55e;
  --text: #f3f5f7;
  --muted: #9aa6b2;
  --user: #243241;
  --assistant: #1f2a1f;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(circle at top, #1c2836 0%, var(--bg) 55%);
  color: var(--text);
}

.app {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: clamp(16px, 4vw, 24px);
}

.app[hidden],
.login-screen[hidden] {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(100%, 420px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(22, 29, 38, 0.88);
  padding: 20px;
}

.login-card p {
  color: var(--muted);
  line-height: 1.35;
}

.login-card input {
  width: 100%;
  border: 1px solid #334155;
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
  font-size: 16px;
  margin: 8px 0 12px;
}

.login-card button {
  width: 100%;
}

.login-status {
  min-height: 22px;
  margin: 12px 0 0;
  color: #fda4af;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.75rem, 6vw, 2rem);
  line-height: 1.1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 18px 0;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  background: var(--accent);
  color: #031407;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
}

button.secondary {
  background: #334155;
  color: #e2e8f0;
}

button.danger {
  background: #7f1d1d;
  color: #fee2e2;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--muted);
  line-height: 1.25;
}

.checkbox input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.voice-controls {
  display: grid;
  grid-template-columns: 160px 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.voice-controls label {
  color: var(--muted);
}

.voice-controls select,
.text-form input,
.memory-form input {
  border: 1px solid #334155;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
  min-width: 0;
  font-size: 16px;
}

.text-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 12px;
}

.status {
  min-height: 22px;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.chat {
  display: grid;
  gap: 10px;
  margin: 12px 0 18px;
}

.msg {
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user {
  background: var(--user);
}

.msg.assistant {
  background: var(--assistant);
}

.food-panel,
.memory-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(22, 29, 38, 0.72);
  padding: 16px;
  margin: 18px 0;
}

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

.panel-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.food-header h2,
.memory-header h2 {
  font-size: 1rem;
  margin: 0;
}

.panel-content[hidden] {
  display: none;
}

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

.food-summary div,
.food-item,
.memory-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.food-summary div {
  padding: 10px;
  min-width: 0;
}

.food-summary strong {
  display: block;
  font-size: 1.35rem;
}

.food-summary span {
  color: var(--muted);
  font-size: 0.84rem;
}

.food-progress {
  height: 10px;
  border-radius: 999px;
  background: #0b1118;
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 12px 0;
}

.food-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 160ms ease;
}

.food-progress-bar.over {
  background: #ef4444;
}

.food-list,
.memory-list {
  display: grid;
  gap: 8px;
}

.food-item {
  padding: 9px 10px;
}

.food-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.food-item span {
  color: #bbf7d0;
  font-size: 0.9rem;
}

.food-item p {
  color: var(--muted);
  margin: 5px 0 0;
  line-height: 1.35;
}

.empty-food,
.empty-memory {
  color: var(--muted);
  margin: 0;
}

.memory-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.45fr) 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.memory-form input {
  border-radius: 8px;
  background: var(--panel-soft);
}

.profile-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.profile-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #111923;
  min-width: 0;
}

.profile-item strong {
  display: block;
  color: #cbd5e1;
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.profile-item span {
  color: var(--text);
  overflow-wrap: anywhere;
}

.memory-item {
  padding: 10px;
}

.memory-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #cbd5e1;
}

.memory-meta strong,
.memory-meta span {
  overflow-wrap: anywhere;
}

.memory-meta span {
  color: var(--muted);
  font-size: 0.82rem;
}

.memory-item p {
  margin: 8px 0;
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

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

.memory-actions button {
  border-radius: 8px;
  padding: 8px 10px;
}

@media (max-width: 700px) {
  .app {
    padding: 16px 12px 24px;
  }

  .controls {
    align-items: stretch;
    gap: 10px;
  }

  .controls button,
  .voice-controls button,
  .voice-controls select,
  .text-form button,
  .memory-form button,
  .food-header button,
  .memory-header button,
  .panel-header-actions {
    width: 100%;
  }

  .checkbox {
    width: 100%;
    align-items: flex-start;
  }

  .voice-controls,
  .text-form,
  .memory-form,
  .profile-summary,
  .food-summary {
    grid-template-columns: 1fr;
  }

  .voice-controls,
  .text-form {
    gap: 8px;
  }

  .food-panel,
  .memory-panel {
    padding: 14px 12px;
    margin: 14px 0;
  }

  .food-header,
  .memory-header {
    align-items: stretch;
  }

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

  .memory-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

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

  .memory-actions button {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 430px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .food-header,
  .memory-header {
    flex-direction: column;
  }

  .food-summary strong {
    font-size: 1.2rem;
  }

  .msg {
    border-radius: 10px;
  }
}

@media (min-width: 701px) {
  .chat {
    max-height: 360px;
    overflow-y: auto;
  }
}
