:root {
  --bg: #edf1f4;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #dde3ea;
  --accent: #0e7490;
  --accent-soft: #e0f2f5;
  --amber: #b45309;
  --amber-soft: #fdf1dd;
  --green: #047857;
  --green-soft: #e2f5ee;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
}

.hidden {
  display: none !important;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.gate-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  color: #155e75;
}

.gate-card p {
  color: var(--muted);
  margin: 0 0 18px;
}

.gate-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  letter-spacing: 0.12em;
  margin-bottom: 14px;
}

.gate-card button,
.primary-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
}

.gate-error {
  color: var(--danger);
  min-height: 20px;
  margin: 10px 0 0;
}

.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.landing-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 34px 28px;
  text-align: center;
}

.landing-card h1 {
  margin: 0 0 8px;
  font-size: 30px;
  color: #155e75;
}

.landing-card p {
  color: var(--muted);
  margin: 0 0 22px;
}

.landing-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  text-align: center;
  font-size: 16px;
}

.landing-card button {
  width: 100%;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 16px;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  color: #155e75;
}

.sub {
  font-size: 12px;
  color: var(--muted);
}

.identity {
  display: flex;
  gap: 8px;
}

.whoami {
  color: #0f3a4a;
  font-weight: 600;
  font-size: 14px;
}

.identity input {
  width: 130px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

main {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.student-main {
  max-width: 760px;
}

.task-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: #e2e8ee;
  border-radius: 10px;
  padding: 6px;
  margin-bottom: 16px;
}

.task-btn {
  background: transparent;
  border-radius: 7px;
  padding: 12px 10px;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.35;
}

.task-btn span {
  font-weight: 400;
  font-size: 13px;
}

.task-btn.active {
  background: var(--card);
  color: #155e75;
  box-shadow: var(--shadow);
}

.task-panel {
  display: none;
}

.task-panel.active {
  display: block;
}

.panel-head {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #0f3a4a;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.suggestions button {
  background: var(--accent-soft);
  color: #0c5a6e;
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 13px;
}

.structure-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.diagram-title {
  font-size: 13px;
  font-weight: 600;
  color: #0f3a4a;
  margin-bottom: 10px;
}

.structure-tip {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 10px;
}

.structure-grid {
  display: flex;
  gap: 6px;
}

.seg-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
  background: #f8fafb;
}

.seg-input span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.seg-input input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 4px;
  text-align: center;
  font-size: 13px;
}

.structure-btn {
  margin-top: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
}

.region-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.region-row {
  display: flex;
  gap: 8px;
}

.region-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
}

.region-row .structure-btn {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
}

.region-result {
  margin-top: 10px;
  font-size: 14px;
  color: #0f3a4a;
  min-height: 20px;
}

.region-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.region-block {
  background: var(--green-soft);
  color: #065f46;
  border: 1px solid #b7e2d2;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

.region-open-btn {
  width: 100%;
  padding: 10px 12px;
  background: var(--green-soft);
  color: #065f46;
  border: 1px solid #b7e2d2;
  border-radius: var(--radius);
  font-weight: 600;
  margin-bottom: 12px;
}

.family-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.family-item {
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.family-item .role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  min-height: 18px;
}

.family-item .id-text {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  color: #0f3a4a;
}

.id-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.id-chip {
  background: var(--accent-soft);
  border: 1px solid #bfe0e8;
  border-radius: 8px;
  padding: 9px 11px;
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
  color: #0c5a6e;
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
}

.id-chip.selected {
  outline: 3px solid var(--amber);
}

.identity-slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.identity-slot {
  min-height: 64px;
  border: 2px dashed #b9c6d1;
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px;
  text-align: center;
  transition: background 0.2s;
}

.identity-slot .role-name {
  font-weight: 700;
  color: #0f3a4a;
  margin-bottom: 6px;
}

.identity-slot .slot-code {
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.identity-slot.correct {
  border-color: var(--green);
  background: var(--green-soft);
}

.identity-slot.wrong {
  border-color: var(--danger);
  background: #fee2e2;
}

.family-result {
  margin: 8px 0;
  font-size: 14px;
  color: #0f3a4a;
  min-height: 20px;
}

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

.family-actions .structure-btn {
  flex: 1;
}

.structure-btn.ghost {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
}

.rule-port {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.rule-port textarea {
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  resize: vertical;
  font: inherit;
}

.region-manual {
  display: flex;
  gap: 8px;
  padding: 10px 18px 0;
}

.region-manual input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 12px;
}

.region-manual button {
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: 7px;
  white-space: nowrap;
}

.region-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 18px 0;
}

.region-tab {
  padding: 8px 12px;
  background: #f2f6f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.region-tab.active {
  background: var(--accent-soft);
  color: #0c5a6e;
  border-color: #bfe0e8;
  font-weight: 600;
}

.region-panel {
  display: block;
}

.bridge-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.bridge-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.bridge-chips span {
  background: var(--amber-soft);
  color: #7c4a03;
  border: 1px solid #f0d29a;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

.bridge-text {
  color: #0f3a4a;
  font-size: 14px;
  margin: 0 0 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 80vh;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  color: #0f3a4a;
}

.modal-head button {
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.modal-list {
  padding: 14px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.modal-item {
  background: #f2f6f8;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 8px;
  text-align: center;
  font-size: 14px;
}

.modal-result {
  padding: 10px 18px 16px;
  color: var(--green);
  font-size: 14px;
  min-height: 20px;
}

.video-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.video-link {
  background: #eef6ff;
  color: #1d4ed8;
  border: 1px solid #c7dbff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  text-decoration: none;
}

.visual-card {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
}

.visual-card .visual-title {
  font-weight: 700;
  color: #0f3a4a;
  margin-bottom: 10px;
}

.visual-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.slots {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}

.slot {
  background: var(--accent-soft);
  color: #0c5a6e;
  border-radius: 5px;
  text-align: center;
  padding: 6px 2px;
  font-size: 12px;
}

.slot.x {
  background: var(--amber);
  color: #fff;
  font-weight: 700;
}

.twin-row {
  display: flex;
  gap: 10px;
}

.twin {
  flex: 1;
  background: #fff7ed;
  border: 1px solid #f4d5a6;
  border-radius: 8px;
  text-align: center;
  padding: 12px 6px;
  font-size: 14px;
}

.addr-tree {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.addr-tree span {
  background: var(--green-soft);
  color: #065f46;
  border-radius: 7px;
  padding: 10px 12px;
  font-weight: 600;
}

.addr-tree b {
  color: var(--muted);
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 44px;
}

.bars span {
  flex: 1;
  background: #0f172a;
  border-radius: 2px;
}

.bars span:nth-child(1) { height: 32%; }
.bars span:nth-child(2) { height: 68%; }
.bars span:nth-child(3) { height: 46%; }
.bars span:nth-child(4) { height: 86%; }
.bars span:nth-child(5) { height: 58%; }

.step-title {
  font-size: 15px;
  font-weight: 700;
  color: #0f3a4a;
  margin-bottom: 8px;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.char-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.char-avatar {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 6px;
}

.char-avatar-img {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 6px;
  border: 2px solid #bfe0e8;
  display: block;
}

.char-name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

.char-preview {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
  min-height: 34px;
}

.char-card button {
  width: 100%;
  padding: 8px 10px;
  background: var(--accent-soft);
  color: #0c5a6e;
  border-radius: 999px;
  font-weight: 600;
}

.char-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.info-card {
  background: #fff7ed;
  border: 1px solid #f4d5a6;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
}

.info-card .label {
  color: var(--amber);
  font-size: 11px;
  display: block;
}

.drop-zone {
  min-height: 72px;
  border: 2px dashed #b9c6d1;
  border-radius: var(--radius);
  background: #fbfcfe;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}

.drop-zone > span {
  color: var(--muted);
  font-size: 12px;
}

.plan-card {
  background: var(--accent-soft);
  border: 1px solid #bfe0e8;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}

.plan-card .label {
  color: #0c5a6e;
  font-size: 11px;
  display: block;
}

.code-preview {
  margin-top: 10px;
  font-size: 13px;
  color: #0f3a4a;
  min-height: 20px;
}

.check-result {
  margin-top: 10px;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
}

.check-result.success {
  background: var(--green-soft);
  border: 1px solid #b7e2d2;
  color: #065f46;
}

.check-result.notice {
  background: var(--amber-soft);
  border: 1px solid #f0d29a;
  color: #7c4a03;
}

.card-output {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.card-output img {
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-output .primary-btn {
  width: auto;
  padding: 10px 18px;
}

.chat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 260px;
  max-height: 48vh;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: #f2f6f8;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg.bot a {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

.msg.bot strong {
  color: #0f3a4a;
}

.msg.bot .md-h {
  display: block;
  font-size: 15px;
  margin: 2px 0 6px;
}

.msg.bot .md-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 8px 0;
}

.speak-btn {
  margin-top: 8px;
  background: var(--accent-soft);
  color: #0c5a6e;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
}

.msg.meta {
  align-self: center;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  border-radius: 999px;
  padding: 5px 12px;
}

.composer {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.composer .suggestions {
  flex-basis: 100%;
  margin-bottom: 8px;
}

.composer input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.composer button {
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
}

.composer .img-btn {
  background: var(--amber);
  color: #fff;
  white-space: nowrap;
}

.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.msg img {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
}

.img-caption {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.round-badge {
  display: inline-block;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* Teacher dashboard */
.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.kpi .num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  color: #0f3a4a;
}

.kpi .label {
  color: var(--muted);
  font-size: 13px;
}

.kpi.kpi-amber {
  border-left-color: var(--amber);
}

.kpi.kpi-green {
  border-left-color: var(--green);
}

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card.wide {
  grid-column: 1 / -1;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #0f3a4a;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  background: #e6ebf0;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.bar-fill.amber {
  background: var(--amber);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0;
}

.tag {
  background: var(--accent-soft);
  color: #0c5a6e;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
}

.recent-item {
  display: grid;
  grid-template-columns: 90px 110px 90px 60px 1fr;
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid #eef1f4;
  padding: 9px 2px;
  font-size: 13px;
}

.recent-item:last-child {
  border-bottom: 0;
}

.recent-item .text {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.toolbar select,
.toolbar input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.toolbar .btn {
  padding: 9px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
}

.toolbar .btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.records-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}

.records-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.records-panel th,
.records-panel td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #eef1f4;
  vertical-align: top;
}

.records-panel th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.records-panel td {
  max-width: 260px;
  word-break: break-word;
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .identity input {
    flex: 1;
    width: auto;
  }

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

  .card.wide {
    grid-column: auto;
  }

  .recent-item {
    grid-template-columns: 70px 1fr;
  }

  .recent-item .task,
  .recent-item .round {
    display: none;
  }
}

/* UI polish */
body {
  background: linear-gradient(180deg, #f2f7fa 0%, #eaf1f5 100%);
}

.landing-card {
  border-radius: 18px;
  border: 1px solid #d6e4ea;
  box-shadow: 0 18px 50px rgba(15, 58, 74, 0.14);
  position: relative;
  overflow: hidden;
}

.landing-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, #0e7490, #14b8a6, #f59e0b);
}

.topbar {
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06);
}

.task-switch {
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}

.task-btn {
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.task-btn.active {
  transform: translateY(-1px);
}

.panel-head,
.family-card,
.rule-port,
.bridge-card,
.structure-card,
.region-card,
.card,
.char-card,
.chat {
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

.structure-btn,
.primary-btn,
.region-open-btn,
.composer button,
.char-card button,
.landing-card button,
.modal-item,
.region-tab,
.region-manual button {
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.structure-btn:active,
.primary-btn:active,
.composer button:active,
.landing-card button:active {
  transform: scale(0.98);
}

.structure-btn:hover,
.primary-btn:hover,
.composer button:hover,
.landing-card button:hover {
  filter: brightness(1.05);
  box-shadow: 0 4px 12px rgba(14, 116, 144, 0.2);
}

.modal-card {
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  border: 1px solid #d6e4ea;
}

.modal-head {
  background: linear-gradient(135deg, #0e7490, #0f9d8f);
  color: #fff;
  border-bottom: 0;
}

.modal-head button {
  color: #fff;
}

.region-tabs {
  background: #f2f7fa;
  border-bottom: 1px solid #e3ecf1;
  padding-bottom: 10px;
}

.region-tab {
  border-radius: 999px;
  padding: 9px 14px;
  transition: all 0.15s ease;
}

.region-tab.active {
  background: #0e7490;
  color: #fff;
  box-shadow: 0 3px 10px rgba(14, 116, 144, 0.25);
}

.region-manual {
  padding-top: 14px;
}

.region-manual input {
  border-radius: 10px;
  padding: 11px 13px;
}

.region-manual button {
  border-radius: 10px;
}

.modal-item {
  border-radius: 10px;
  border-color: #d6e4ea;
}

.modal-item:hover {
  background: #e0f2f5;
  transform: translateY(-1px);
}

.modal-result,
.region-result {
  color: #0f766e;
  font-weight: 600;
}

.chat {
  border-radius: 14px;
}

.msg.bot {
  background: #ffffff;
  border-color: #e3ecf1;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}

.msg.user {
  background: linear-gradient(135deg, #0e7490, #0f9d8f);
}

.composer input {
  border-radius: 12px;
}

.composer input:focus {
  outline: none;
  border-color: #0e7490;
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.15);
}

.id-chip {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.07);
}

.identity-slot {
  border-radius: 12px;
  background: #ffffff;
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.04);
}

.identity-slot.correct {
  box-shadow: 0 0 0 2px rgba(4, 120, 87, 0.25);
}

.identity-slot.wrong {
  box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.2);
}

.topbar .whoami {
  text-align: right;
}

@media (max-width: 760px) {
  .topbar {
    text-align: center;
  }

  .topbar .whoami {
    text-align: center;
    width: 100%;
  }
}

.match-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.match-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #f0d29a;
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 13px;
  color: #7c4a03;
}

.match-chip img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-wrap {
  position: relative;
  display: inline-block;
}

.avatar-wrap .char-avatar-img {
  display: block;
  margin: 0 auto;
}

.gender-tag {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  line-height: 1;
}

.avatar-wrap.male .gender-tag {
  background: #2563eb;
}

.avatar-wrap.female .gender-tag {
  background: #db2777;
}

.match-chip .avatar-wrap img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
}

.char-avatar-svg {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 6px;
  border: 2px solid #bfe0e8;
  background: #eef4f8;
}

.char-avatar-svg svg {
  display: block;
}

.match-chip .char-avatar-svg.small {
  width: 28px;
  height: 28px;
  margin: 0;
  border-width: 1px;
}

.match-chip .char-avatar-svg.small svg {
  width: 28px;
  height: 28px;
}
